Ejemplo n.º 1
0
    def create_colors(self, n):
        """
        Create the colors based on how many legend items there are (n).

        The idea is to start off with one color, assign it to the 1st legend
        value, then find that color's complement and assign it to the 2nd
        legend value. Then, move around the color wheel by some degree,
        probably like so:

          <insert math>

        We are limited to only using 1/2 of the circle
        because we use the other half for the complements.

        1.  Split the circle into n parts.
        2.  reorganize into alternations
            1 2 3 4 5 6 7 8  -->
            1 3 5 7 2 4 6 8
        """
        spacing = 360 / n
        colors = []
        for val in wm_utils.frange(0, 360, spacing):
            hsl = (val / 360, 1, 0.75)
            colors.append(colorsys.hsv_to_rgb(*hsl))

        # convert from 0-1 to 0-255 and return
        colors = [tuple(int(i * 255) for i in color) for color in colors]

        # Alternate colors across the circle
        colors = colors[::2] + colors[1::2]
        return colors
Ejemplo n.º 2
0
    def create_colors(self, n):
        """
        Create the colors based on how many legend items there are (n).

        The idea is to start off with one color, assign it to the 1st legend
        value, then find that color's complement and assign it to the 2nd
        legend value. Then, move around the color wheel by some degree,
        probably like so:

          <insert math>

        We are limited to only using 1/2 of the circle
        because we use the other half for the complements.

        1.  Split the circle into n parts.
        2.  reorganize into alternations
            1 2 3 4 5 6 7 8  -->
            1 3 5 7 2 4 6 8
        """
        spacing = 360 / n
        colors = []
        for val in wm_utils.frange(0, 360, spacing):
            hsl = (val/360, 1, 0.75)
            colors.append(colorsys.hsv_to_rgb(*hsl))

        # convert from 0-1 to 0-255 and return
        colors = [tuple(int(i*255) for i in color) for color in colors]

        # Alternate colors across the circle
        colors = colors[::2] + colors[1::2]
        return colors
Ejemplo n.º 3
0
    def calc_ticks(self):
        """
        Calculates the tick marks' display string, value, and pixel value.

        High values are at the top of the scale, low at the bottom.
        """
        # First we need to determine the values for the ticks.
        pr = self.plot_range[1] - self.plot_range[0]
        spacing = pr / (self.num_ticks - 1)

        tick_values = wm_utils.frange(self.plot_range[0],
                                      self.plot_range[1] + 1, spacing)

        ticks = []
        for tick in tick_values:
            string = "{:.3f}".format(tick)
            value = tick
            # `grad_end_y - 1` so that the bottom tick is aligned correctly.
            pixel = wm_utils.rescale(tick, self.plot_range,
                                     (self.grad_end_y - 1, self.grad_start_y))
            # Putting gradient_end_y as the "low" for rescale makes the
            # high value be at the north end and the low value at the south.
            ticks.append((string, value, pixel))

        return ticks
Ejemplo n.º 4
0
    def calc_ticks(self):
        """
        Calculates the tick marks' display string, value, and pixel value.

        High values are at the top of the scale, low at the bottom.
        """
        # First we need to determine the values for the ticks.
        pr = self.plot_range[1] - self.plot_range[0]
        spacing = pr / (self.num_ticks - 1)

        tick_values = wm_utils.frange(self.plot_range[0],
                                      self.plot_range[1] + 1,
                                      spacing)

        ticks = []
        for tick in tick_values:
            string = "{:.3f}".format(tick)
            value = tick
            # `grad_end_y - 1` so that the bottom tick is aligned correctly.
            pixel = wm_utils.rescale(tick,
                                     self.plot_range,
                                     (self.grad_end_y - 1, self.grad_start_y))
            # Putting gradient_end_y as the "low" for rescale makes the
            # high value be at the north end and the low value at the south.
            ticks.append((string, value, pixel))

        return ticks