Draw an RGB triangle legend on the desired axis

def _rgb_triangle(ax, r_label, g_label, b_label, loc):
        """
        Draw an RGB triangle legend on the desired axis
        """
        if not loc in range(1, 11):
            loc = 2

        from mpl_toolkits.axes_grid1.inset_locator import inset_axes
        inset_ax = inset_axes(ax, width=1, height=1, loc=loc)
        mesh = 35
        x = []
        y = []
        color = []
        for r in range(0, mesh):
            for g in range(0, mesh):
                for b in range(0, mesh):
                    if not (r == 0 and b == 0 and g == 0):
                        r1 = r / (r + g + b)
                        g1 = g / (r + g + b)
                        b1 = b / (r + g + b)
                        x.append(0.33 * (2. * g1 + r1) / (r1 + b1 + g1))
                        y.append(0.33 * np.sqrt(3) * r1 / (r1 + b1 + g1))
                        rc = math.sqrt(r ** 2 / (r ** 2 + g ** 2 + b ** 2))
                        gc = math.sqrt(g ** 2 / (r ** 2 + g ** 2 + b ** 2))
                        bc = math.sqrt(b ** 2 / (r ** 2 + g ** 2 + b ** 2))
                        color.append([rc, gc, bc])

        # x = [n + 0.25 for n in x]  # nudge x coordinates
        # y = [n + (max_y - 1) for n in y]  # shift y coordinates to top
        # plot the triangle
        inset_ax.scatter(x, y, s=7, marker='.', edgecolor=color)
        inset_ax.set_xlim([-0.35, 1.00])
        inset_ax.set_ylim([-0.35, 1.00])

        # add the labels
        inset_ax.text(0.70, -0.2, g_label, fontsize=13,
                      family='Times New Roman', color=(0, 0, 0),
                      horizontalalignment='left')
        inset_ax.text(0.325, 0.70, r_label, fontsize=13,
                      family='Times New Roman', color=(0, 0, 0),
                      horizontalalignment='center')
        inset_ax.text(-0.05, -0.2, b_label, fontsize=13,
                      family='Times New Roman', color=(0, 0, 0),
                      horizontalalignment='right')

        inset_ax.get_xaxis().set_visible(False)
        inset_ax.get_yaxis().set_visible(False)