Python matplotlib.cycler() Examples

The following are 17 code examples for showing how to use matplotlib.cycler(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module matplotlib , or try the search function .

Example 1
Project: python3_ios   Author: holzschu   File: test_colors.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_cn():
    matplotlib.rcParams['axes.prop_cycle'] = cycler('color',
                                                    ['blue', 'r'])
    assert mcolors.to_hex("C0") == '#0000ff'
    assert mcolors.to_hex("C1") == '#ff0000'

    matplotlib.rcParams['axes.prop_cycle'] = cycler('color',
                                                    ['xkcd:blue', 'r'])
    assert mcolors.to_hex("C0") == '#0343df'
    assert mcolors.to_hex("C1") == '#ff0000'

    matplotlib.rcParams['axes.prop_cycle'] = cycler('color', ['8e4585', 'r'])

    assert mcolors.to_hex("C0") == '#8e4585'
    # if '8e4585' gets parsed as a float before it gets detected as a hex
    # colour it will be interpreted as a very large number.
    # this mustn't happen.
    assert mcolors.to_rgb("C0")[0] != np.inf 
Example 2
Project: coffeegrindsize   Author: jgagneastro   File: test_colors.py    License: MIT License 6 votes vote down vote up
def test_cn():
    matplotlib.rcParams['axes.prop_cycle'] = cycler('color',
                                                    ['blue', 'r'])
    assert mcolors.to_hex("C0") == '#0000ff'
    assert mcolors.to_hex("C1") == '#ff0000'

    matplotlib.rcParams['axes.prop_cycle'] = cycler('color',
                                                    ['xkcd:blue', 'r'])
    assert mcolors.to_hex("C0") == '#0343df'
    assert mcolors.to_hex("C1") == '#ff0000'

    matplotlib.rcParams['axes.prop_cycle'] = cycler('color', ['8e4585', 'r'])

    assert mcolors.to_hex("C0") == '#8e4585'
    # if '8e4585' gets parsed as a float before it gets detected as a hex
    # colour it will be interpreted as a very large number.
    # this mustn't happen.
    assert mcolors.to_rgb("C0")[0] != np.inf 
Example 3
Project: twitter-stock-recommendation   Author: alvarobartt   File: test_colors.py    License: MIT License 6 votes vote down vote up
def test_cn():
    matplotlib.rcParams['axes.prop_cycle'] = cycler('color',
                                                    ['blue', 'r'])
    assert mcolors.to_hex("C0") == '#0000ff'
    assert mcolors.to_hex("C1") == '#ff0000'

    matplotlib.rcParams['axes.prop_cycle'] = cycler('color',
                                                    ['xkcd:blue', 'r'])
    assert mcolors.to_hex("C0") == '#0343df'
    assert mcolors.to_hex("C1") == '#ff0000'

    matplotlib.rcParams['axes.prop_cycle'] = cycler('color', ['8e4585', 'r'])

    assert mcolors.to_hex("C0") == '#8e4585'
    # if '8e4585' gets parsed as a float before it gets detected as a hex
    # colour it will be interpreted as a very large number.
    # this mustn't happen.
    assert mcolors.to_rgb("C0")[0] != np.inf 
Example 4
Project: recruit   Author: Frank-qlu   File: test_frame.py    License: Apache License 2.0 5 votes vote down vote up
def test_default_color_cycle(self):
        import matplotlib.pyplot as plt
        import cycler
        colors = list('rgbk')
        plt.rcParams['axes.prop_cycle'] = cycler.cycler('color', colors)

        df = DataFrame(randn(5, 3))
        ax = df.plot()

        expected = self._unpack_cycler(plt.rcParams)[:3]
        self._check_colors(ax.get_lines(), linecolors=expected) 
Example 5
Project: recruit   Author: Frank-qlu   File: test_frame.py    License: Apache License 2.0 5 votes vote down vote up
def test_rcParams_bar_colors(self):
        import matplotlib as mpl
        color_tuples = [(0.9, 0, 0, 1), (0, 0.9, 0, 1), (0, 0, 0.9, 1)]
        with mpl.rc_context(
                rc={'axes.prop_cycle': mpl.cycler("color", color_tuples)}):
            barplot = pd.DataFrame([[1, 2, 3]]).plot(kind="bar")
        assert color_tuples == [c.get_facecolor() for c in barplot.patches] 
Example 6
Project: vnpy_crypto   Author: birforce   File: test_frame.py    License: MIT License 5 votes vote down vote up
def test_default_color_cycle(self):
        import matplotlib.pyplot as plt
        colors = list('rgbk')
        if self.mpl_ge_1_5_0:
            import cycler
            plt.rcParams['axes.prop_cycle'] = cycler.cycler('color', colors)
        else:
            plt.rcParams['axes.color_cycle'] = colors

        df = DataFrame(randn(5, 3))
        ax = df.plot()

        expected = self._maybe_unpack_cycler(plt.rcParams)[:3]
        self._check_colors(ax.get_lines(), linecolors=expected) 
Example 7
Project: vnpy_crypto   Author: birforce   File: test_frame.py    License: MIT License 5 votes vote down vote up
def test_rcParams_bar_colors(self):
        import matplotlib as mpl
        color_tuples = [(0.9, 0, 0, 1), (0, 0.9, 0, 1), (0, 0, 0.9, 1)]
        try:  # mpl 1.5
            with mpl.rc_context(
                    rc={'axes.prop_cycle': mpl.cycler("color", color_tuples)}):
                barplot = pd.DataFrame([[1, 2, 3]]).plot(kind="bar")
        except (AttributeError, KeyError):  # mpl 1.4
            with mpl.rc_context(rc={'axes.color_cycle': color_tuples}):
                barplot = pd.DataFrame([[1, 2, 3]]).plot(kind="bar")
        assert color_tuples == [c.get_facecolor() for c in barplot.patches] 
Example 8
def test_default_color_cycle(self):
        import matplotlib.pyplot as plt
        import cycler
        colors = list('rgbk')
        plt.rcParams['axes.prop_cycle'] = cycler.cycler('color', colors)

        df = DataFrame(randn(5, 3))
        ax = df.plot()

        expected = self._unpack_cycler(plt.rcParams)[:3]
        self._check_colors(ax.get_lines(), linecolors=expected) 
Example 9
def test_rcParams_bar_colors(self):
        import matplotlib as mpl
        color_tuples = [(0.9, 0, 0, 1), (0, 0.9, 0, 1), (0, 0, 0.9, 1)]
        with mpl.rc_context(
                rc={'axes.prop_cycle': mpl.cycler("color", color_tuples)}):
            barplot = pd.DataFrame([[1, 2, 3]]).plot(kind="bar")
        assert color_tuples == [c.get_facecolor() for c in barplot.patches] 
Example 10
Project: phy   Author: cortex-lab   File: plot.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        plt.style.use('dark_background')
        mpl.rcParams['toolbar'] = 'None'
        mpl.rcParams['axes.prop_cycle'] = mpl.cycler(color=[DEFAULT_COLOR])
        self.figure = plt.figure()
        self.subplots() 
Example 11
Project: elasticintel   Author: securityclippy   File: test_frame.py    License: GNU General Public License v3.0 5 votes vote down vote up
def test_default_color_cycle(self):
        import matplotlib.pyplot as plt
        colors = list('rgbk')
        if self.mpl_ge_1_5_0:
            import cycler
            plt.rcParams['axes.prop_cycle'] = cycler.cycler('color', colors)
        else:
            plt.rcParams['axes.color_cycle'] = colors

        df = DataFrame(randn(5, 3))
        ax = df.plot()

        expected = self._maybe_unpack_cycler(plt.rcParams)[:3]
        self._check_colors(ax.get_lines(), linecolors=expected) 
Example 12
Project: elasticintel   Author: securityclippy   File: test_frame.py    License: GNU General Public License v3.0 5 votes vote down vote up
def test_rcParams_bar_colors(self):
        import matplotlib as mpl
        color_tuples = [(0.9, 0, 0, 1), (0, 0.9, 0, 1), (0, 0, 0.9, 1)]
        try:  # mpl 1.5
            with mpl.rc_context(
                    rc={'axes.prop_cycle': mpl.cycler("color", color_tuples)}):
                barplot = pd.DataFrame([[1, 2, 3]]).plot(kind="bar")
        except (AttributeError, KeyError):  # mpl 1.4
            with mpl.rc_context(rc={'axes.color_cycle': color_tuples}):
                barplot = pd.DataFrame([[1, 2, 3]]).plot(kind="bar")
        assert color_tuples == [c.get_facecolor() for c in barplot.patches] 
Example 13
Project: coffeegrindsize   Author: jgagneastro   File: test_frame.py    License: MIT License 5 votes vote down vote up
def test_default_color_cycle(self):
        import matplotlib.pyplot as plt
        import cycler
        colors = list('rgbk')
        plt.rcParams['axes.prop_cycle'] = cycler.cycler('color', colors)

        df = DataFrame(randn(5, 3))
        ax = df.plot()

        expected = self._unpack_cycler(plt.rcParams)[:3]
        self._check_colors(ax.get_lines(), linecolors=expected) 
Example 14
Project: coffeegrindsize   Author: jgagneastro   File: test_frame.py    License: MIT License 5 votes vote down vote up
def test_rcParams_bar_colors(self):
        import matplotlib as mpl
        color_tuples = [(0.9, 0, 0, 1), (0, 0.9, 0, 1), (0, 0, 0.9, 1)]
        with mpl.rc_context(
                rc={'axes.prop_cycle': mpl.cycler("color", color_tuples)}):
            barplot = pd.DataFrame([[1, 2, 3]]).plot(kind="bar")
        assert color_tuples == [c.get_facecolor() for c in barplot.patches] 
Example 15
Project: twitter-stock-recommendation   Author: alvarobartt   File: test_frame.py    License: MIT License 5 votes vote down vote up
def test_default_color_cycle(self):
        import matplotlib.pyplot as plt
        colors = list('rgbk')
        if self.mpl_ge_1_5_0:
            import cycler
            plt.rcParams['axes.prop_cycle'] = cycler.cycler('color', colors)
        else:
            plt.rcParams['axes.color_cycle'] = colors

        df = DataFrame(randn(5, 3))
        ax = df.plot()

        expected = self._maybe_unpack_cycler(plt.rcParams)[:3]
        self._check_colors(ax.get_lines(), linecolors=expected) 
Example 16
Project: twitter-stock-recommendation   Author: alvarobartt   File: test_frame.py    License: MIT License 5 votes vote down vote up
def test_rcParams_bar_colors(self):
        import matplotlib as mpl
        color_tuples = [(0.9, 0, 0, 1), (0, 0.9, 0, 1), (0, 0, 0.9, 1)]
        try:  # mpl 1.5
            with mpl.rc_context(
                    rc={'axes.prop_cycle': mpl.cycler("color", color_tuples)}):
                barplot = pd.DataFrame([[1, 2, 3]]).plot(kind="bar")
        except (AttributeError, KeyError):  # mpl 1.4
            with mpl.rc_context(rc={'axes.color_cycle': color_tuples}):
                barplot = pd.DataFrame([[1, 2, 3]]).plot(kind="bar")
        assert color_tuples == [c.get_facecolor() for c in barplot.patches] 
Example 17
Project: sumo   Author: SMTG-UCL   File: bs_plotter.py    License: MIT License 4 votes vote down vote up
def _makedos(self, ax, dos_plotter, dos_options, dos_label=None,
                 plot_legend=True):
        """This is basically the same as the SDOSPlotter get_plot function."""

        # don't use first 4 colours; these are the band structure line colours
        cycle = cycler(
            'color', rcParams['axes.prop_cycle'].by_key()['color'][4:])
        with context({'axes.prop_cycle': cycle}):
            plot_data = dos_plotter.dos_plot_data(**dos_options)

        mask = plot_data['mask']
        energies = plot_data['energies'][mask]
        lines = plot_data['lines']
        spins = [Spin.up] if len(lines[0][0]['dens']) == 1 else \
            [Spin.up, Spin.down]

        # disable y ticks for DOS panel
        ax.tick_params(axis='y', which='both', right=False)

        for line_set in plot_data['lines']:
            for line, spin in it.product(line_set, spins):
                if spin == Spin.up:
                    label = line['label']
                    densities = line['dens'][spin][mask]
                else:
                    label = ""
                    densities = -line['dens'][spin][mask]
                ax.fill_betweenx(energies, densities, 0, lw=0,
                                 facecolor=line['colour'],
                                 alpha=line['alpha'])
                ax.plot(densities, energies, label=label,
                        color=line['colour'])

            # x and y axis reversed versus normal dos plotting
            ax.set_ylim(dos_options['xmin'], dos_options['xmax'])
            ax.set_xlim(plot_data['ymin'], plot_data['ymax'])

            if dos_label is not None:
                ax.set_xlabel(dos_label)

        ax.set_xticklabels([])
        if plot_legend:
            ax.legend(loc=2, frameon=False, ncol=1, bbox_to_anchor=(1., 1.))