コード例 #1
0
def get_default_cdict():
    colors = get_default_colors(norm=True)
    outp = {'red': [], 'green': [], 'blue': []}

    for k, (h, r, g, b) in colors.items():
        outp['red'].append((h, r, r))
        outp['green'].append((h, g, g))
        outp['blue'].append((h, b, b))
    return outp
コード例 #2
0
def get_default_colors(norm=False):
    scale = 1.0 / 255.0 if norm else 1.0
    colors = {
        # Labeled tuples of (height, r, g, b)
        'min': (0, 45, 15, 128),
        'ocean_depth_boundary': (0, 45, 15, 128),
        'ocean_shallow': (70, 87, 63, 153),
        'ocean_coastal': (105, 175, 238, 238),
        'coastline': (110, 194, 178, 128),
        'grass': (120, 65, 152, 10),
        'plains': (160, 130, 123, 69),
        'stone': (200, 136, 140, 141),
        'snow': (230, 240, 240, 240),
        'max': (255, 255, 255, 255)
    }
    return {k: tuple(x * scale for x in y) for k, y in colors.items()}
コード例 #3
0
    def change_catalogue(self, catalogue):
        self.params.blockSignals(True)
        with self.mutex:

            self.catalogue = catalogue

            colors = make_color_dict(self.catalogue['clusters'])
            self.qcolors = {}
            for k, color in colors.items():
                r, g, b = color
                self.qcolors[k] = QT.QColor(r * 255, g * 255, b * 255)

            self.all_plotted_labels = self.catalogue['cluster_labels'].tolist(
            ) + [LABEL_UNCLASSIFIED]

            centers0 = self.catalogue['centers0']
            if centers0.shape[0] > 0:
                self.params['bin_min'] = np.min(centers0) * 1.5
                self.params['bin_max'] = np.max(centers0) * 1.5

            bin_min, bin_max = self.params['bin_min'], self.params['bin_max']
            bin_size = self.params['bin_size']
            self.bins = np.arange(bin_min, bin_max, self.params['bin_size'])

            self.combobox.clear()
            self.combobox.addItems([str(k) for k in self.all_plotted_labels])

        self.on_clear()
        self._max = 10

        _, peak_width, nb_chan = self.catalogue['centers0'].shape
        x, y = [], []
        for c in range(1, nb_chan):
            x.extend([c * peak_width, c * peak_width, np.nan])
            y.extend([-1000, 1000, np.nan])

        self.curve_limit.setData(x=x, y=y, connect='finite')
        self.params.blockSignals(False)
コード例 #4
0
          ['pellet'], ['insured pellet']]

colors = {
    'r1_in': 'red',
    'r1_out': 'lightsalmon',
    'r2_in': 'orange',
    'r2_out': 'bisque',
    'r3_in': 'green',
    'r3_out': 'lightgreen',
    'r4_in': 'blue',
    'r4_out': 'lightblue',
    'pellet': 'aqua',
    'insured pellet': 'brown'
}

for k, v in colors.items():
    col = matplotlib.colors.to_rgba_array(v)[0] * 255
    colors[k] = np.array([int(c) for c in col])

sizes = {
    'r1_in': 1,
    'r1_out': 1,
    'r2_in': 1,
    'r2_out': 1,
    'r3_in': 1,
    'r3_out': 1,
    'r4_in': 1,
    'r4_out': 1,
    'pellet': 3,
    'insured pellet': 3
}
コード例 #5
0
ファイル: __init__.py プロジェクト: schillerlab/sc-toolbox
def colors_overview(colors: Dict, ncols: int = 2, figsize: Tuple[int, int] = (8, 5), save: str = None):
    """
    Draw an overview plot of all used colors

    Args:
        colors: Dictionary of color name and color
        ncols: How many columns for the plot
        figsize: Size of the figure as specified in matplotlib
        save: Path to save the plot to

    Example:
        .. image:: /_images/colors.png
    """
    from matplotlib import colors as mcolors

    # Sort colors by hue, saturation, value and name.
    by_hsv = sorted((tuple(mcolors.rgb_to_hsv(mcolors.to_rgba(color)[:3])), name) for name, color in colors.items())
    sorted_names = [name for hsv, name in by_hsv]

    n = len(sorted_names)
    nrows = n // ncols + 1

    fig, ax = plt.subplots(figsize=figsize)

    # Get height and width
    x, y = fig.get_dpi() * fig.get_size_inches()
    h = y / (nrows + 1)
    w = x / ncols

    for i, name in enumerate(sorted_names):
        col = i % ncols
        row = i // ncols
        y = y - (row * h) - h

        xi_line = w * (col + 0.05)
        xf_line = w * (col + 0.25)
        xi_text = w * (col + 0.3)

        ax.text(
            xi_text,
            y,
            "%s %s" % (name, colors[name]),
            fontsize=(h * 0.4),
            horizontalalignment="left",
            verticalalignment="center",
        )
        ax.hlines(y + h * 0.1, xi_line, xf_line, color=colors[name], linewidth=(h * 0.6))

    ax.set_xlim(0, x)
    ax.set_ylim(0, y)
    ax.set_axis_off()

    fig.subplots_adjust(left=0, right=1, top=1, bottom=0, hspace=0, wspace=0)
    if save:
        print(f"Saving to {save}")
        plt.savefig(save, bbox_to_anchor="tight")
    plt.show()