Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute.
matplotlib.axes.Axes.set_prop_cycle() Function
The Axes.set_prop_cycle() function in axes module of matplotlib library is used to set the property cycle of the Axes.
Syntax: Axes.set_prop_cycle(self, *args, **kwargs)
Parameters: This method accepts the following parameters.
- cycler : This parameter is used to set the given Cycler.
- label : This parameter is the property key.
- values : This parameter is the finite-length iterable of the property values.
Returns:This method does not returns any values.
Below examples illustrate the matplotlib.axes.Axes.set_prop_cycle() function in matplotlib.axes:
Example 1:
# Implementation of matplotlib function from cycler import cycler import numpy as np import matplotlib.pyplot as plt x = np.linspace( 0 , 200 , 10 ) yy = np.transpose([ 2 * np.sin(x + phi) for phi in x]) fig, ax1 = plt.subplots() ax1.set_prop_cycle(color = [ 'magenta' , 'g' , 'y' , 'k' ], lw = [ 1 , 2 , 3 , 4 ]) ax1.plot(yy) ax1.set_title(' matplotlib.axes.Axes.set_prop_cycle() \ Example\n ', fontsize = 12, fontweight =' bold') plt.show() |
Output:
Example 2:
# Implementation of matplotlib function from cycler import cycler import numpy as np import matplotlib.pyplot as plt x = np.linspace( 0 , 3 * np.pi) offsets = np.linspace( 0 , 3 * np.pi, 8 , endpoint = False ) yy = np.transpose([ 2 * np.sin(x + phi) for phi in offsets]) plt.rc( 'lines' , linewidth = 4 ) plt.rc( 'axes' , prop_cycle = (cycler(color = [ 'r' , 'g' , 'purple' , 'orange' ]) + cycler(linestyle = [ '-' , '--' , ':' , '-.' ]))) fig, (ax0, ax1) = plt.subplots(nrows = 2 ) ax0.plot(yy) ax0.set_title('Above example with set_prop_cycle() \ function\n\nSet default color cycle to rgby', fontsize = 12 , fontweight = 'bold' ) ax1.set_prop_cycle(color = [ 'magenta' , 'g' , 'y' , 'k' ], lw = [ 1 , 2 , 3 , 4 ]) ax1.plot(yy) ax1.set_title( 'Set axes color cycle to cmyk' , fontsize = 12 , fontweight = 'bold' ) plt.show() |
Output: