Default color cycle

A color cycle is a list of colors used to control the color of a series of elements automatically, such as each data series in multiline plots. In Matplotlib 2.0, the default color cycle has expanded from 7 to 10 colors using the category10 palette in Data-Driven Documents (D3) https://github.com/d3 and Vega, a declarative language for visualization grammar. These colors are designed to show good contrast between distinct categories. Each color is named 'C0' to 'C9', and can be called in manually by specifying a color in the preset color cycle. Here is a toy example of a multiline plot with each color in the default cycle:

import matplotlib.pyplot as plt
for i in range(10):
plt.plot([i]*5,c='C'+str(i),label='C'+str(i))
plt.xlim(0,5)
plt.legend()
plt.show()

The following is the figure output. The legend displays the name of each color in the default cycle:

To access the hexadecimal codes of the colors, you may use the following code:

import matplotlib as mpl 
mpl.rcParams['axes.prop_cycle']
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.239.107