.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_auto_examples/matplot_cycler.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr__auto_examples_matplot_cycler.py: Matplotlib Cycler ===================================== This files shows inconsistencies when using the MatplotLib plotting functions. :func:`sysplot.get_style` offers a way to fix these issues. .. GENERATED FROM PYTHON SOURCE LINES 7-85 .. rst-class:: sphx-glr-horizontal * .. image-sg:: /_auto_examples/images/sphx_glr_matplot_cycler_001.png :alt: Plot() and Scatter() use independent cyclers, Stem() does not use a cycler :srcset: /_auto_examples/images/sphx_glr_matplot_cycler_001.png :class: sphx-glr-multi-img * .. image-sg:: /_auto_examples/images/sphx_glr_matplot_cycler_002.png :alt: Passing colors means the cycler doesn't advance :srcset: /_auto_examples/images/sphx_glr_matplot_cycler_002.png :class: sphx-glr-multi-img * .. image-sg:: /_auto_examples/images/sphx_glr_matplot_cycler_003.png :alt: Specifying color does advance the cycler only for Plot(), Specifying color and linestyle no longer advance the cycler :srcset: /_auto_examples/images/sphx_glr_matplot_cycler_003.png :class: sphx-glr-multi-img * .. image-sg:: /_auto_examples/images/sphx_glr_matplot_cycler_004.png :alt: get_style() fixes any inconsistencies :srcset: /_auto_examples/images/sphx_glr_matplot_cycler_004.png :class: sphx-glr-multi-img .. code-block:: Python # _________________________________________________________ # Scatter and Plot have different Cyclers import numpy as np import matplotlib.pyplot as plt x = np.arange(10) y = np.sin(x) fig, axes = plt.subplots(1, 2, figsize=(10, 5)) axes[0].plot(x, y) axes[0].plot(x + 1, y + 1) axes[0].scatter(x + 2, y + 2) axes[0].scatter(x + 3, y + 3) axes[0].set_title("Plot() and Scatter() use independent cyclers") axes[1].stem(x, y) axes[1].stem(x + 1, y + 1, bottom=1) axes[1].set_title("Stem() does not use a cycler") plt.show() # _________________________________________________________ # Cycler does not advance with color= fig, ax = plt.subplots(1, 1, figsize=(5, 5)) ax.plot(x, y, color="gray") ax.plot(x + 1, y + 1) ax.scatter(x + 2, y + 2, color="gray") ax.scatter( x + 3, y + 3, ) ax.set_title("Passing colors means the cycler doesn't advance") plt.show() # _________________________________________________________ # Sysplot makes the previos a mess import sysplot as ssp # # noqa: E402 ssp.apply_config() fig, axes = plt.subplots(1, 2, figsize=(10, 5)) axes[0].plot(x, y, color="gray") axes[0].plot(x + 1, y + 1) axes[0].scatter(x + 2, y + 2, color="gray") axes[0].scatter(x + 3, y + 3) axes[0].set_title("Specifying color does advance the cycler only for Plot()") axes[1].plot(x, y, color="gray", linestyle=":") axes[1].plot(x + 1, y + 1) axes[1].scatter(x + 2, y + 2, color="gray", linestyle=":") axes[1].scatter(x + 3, y + 3) axes[1].set_title("Specifying color and linestyle no longer advance the cycler") plt.show() # _________________________________________________________ # get_style() fixes everything ssp.apply_config() fig, ax = plt.subplots(1, 1, figsize=(5, 5)) ax.plot(x, y, **ssp.get_style(index=7)) ax.plot(x + 1, y + 1) ax.scatter(x + 2, y + 2, **ssp.get_style(ax=ax)) ax.scatter(x + 3, y + 3, **ssp.get_style(ax=ax)) ax.set_title("get_style() fixes any inconsistencies") plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.982 seconds) .. _sphx_glr_download__auto_examples_matplot_cycler.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: matplot_cycler.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: matplot_cycler.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: matplot_cycler.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_