Demo of custom property-cycle settings to control colors and other style properties for multi-line plots.
Note
More complete documentation of the cycler
API can be found here.
This example demonstrates two different APIs:
Setting the rc parameter specifying the default property cycle. This affects all subsequent Axes (but not Axes already created).
Setting the property cycle for a single pair of Axes.
from cycler import cycler import matplotlib.pyplot as plt import numpy as np
First we'll generate some sample data, in this case, four offset sine curves.
Now yy
has shape
So yy[:, i]
will give you the i
-th offset sine curve. Let's set the default prop_cycle
using matplotlib.pyplot.rc()
. We'll combine a color cycler and a linestyle cycler by adding (+
) two cycler
's together. See the bottom of this tutorial for more information about combining different cyclers.
Now we'll generate a figure with two Axes, one on top of the other. On the first axis, we'll plot with the default cycler. On the second axis, we'll set the prop_cycle
using matplotlib.axes.Axes.set_prop_cycle()
, which will only set the prop_cycle
for this matplotlib.axes.Axes
instance. We'll use a second cycler
that combines a color cycler and a linewidth cycler.
prop_cycle
in the matplotlibrc
file or style files#
Remember, a custom cycler can be set in your matplotlibrc
file or a style file (style.mplstyle
) under axes.prop_cycle
:
axes.prop_cycle : cycler(color='bgrcmyk')Cycling through multiple properties#
You can add cyclers:
from cycler import cycler cc = (cycler(color=list('rgb')) + cycler(linestyle=['-', '--', '-.'])) for d in cc: print(d)
Results in:
{'color': 'r', 'linestyle': '-'} {'color': 'g', 'linestyle': '--'} {'color': 'b', 'linestyle': '-.'}
You can multiply cyclers:
from cycler import cycler cc = (cycler(color=list('rgb')) * cycler(linestyle=['-', '--', '-.'])) for d in cc: print(d)
Results in:
{'color': 'r', 'linestyle': '-'} {'color': 'r', 'linestyle': '--'} {'color': 'r', 'linestyle': '-.'} {'color': 'g', 'linestyle': '-'} {'color': 'g', 'linestyle': '--'} {'color': 'g', 'linestyle': '-.'} {'color': 'b', 'linestyle': '-'} {'color': 'b', 'linestyle': '--'} {'color': 'b', 'linestyle': '-.'}
Gallery generated by Sphinx-Gallery
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4