Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b1e0a18

Browse files
authored
Merge pull request #6634 from efiring/show_color_cycle
DOC: add example to show the full default color cycle
2 parents 11226f8 + 9ed73a6 commit b1e0a18

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

examples/color/color_cycle_default.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
Display the colors from the default prop_cycle.
3+
"""
4+
5+
import numpy as np
6+
import matplotlib.pyplot as plt
7+
8+
prop_cycle = plt.rcParams['axes.prop_cycle']
9+
colors = prop_cycle.by_key()['color']
10+
11+
lwbase = plt.rcParams['lines.linewidth']
12+
thin = float('%.1f' % (lwbase / 2))
13+
thick = lwbase * 3
14+
15+
fig, axs = plt.subplots(nrows=2, ncols=2, sharex=True, sharey=True)
16+
for icol in range(2):
17+
if icol == 0:
18+
lwx, lwy = thin, lwbase
19+
else:
20+
lwx, lwy = lwbase, thick
21+
for irow in range(2):
22+
for i, color in enumerate(colors):
23+
axs[irow, icol].axhline(i, color=color, lw=lwx)
24+
axs[irow, icol].axvline(i, color=color, lw=lwy)
25+
26+
axs[1, icol].set_facecolor('k')
27+
axs[1, icol].xaxis.set_ticks(np.arange(0, 10, 2))
28+
axs[0, icol].set_title('line widths (pts): %.1f, %.1f' % (lwx, lwy),
29+
fontsize='medium')
30+
31+
for irow in range(2):
32+
axs[irow, 0].yaxis.set_ticks(np.arange(0, 10, 2))
33+
34+
fig.suptitle('Colors in the default prop_cycle', fontsize='large')
35+
36+
plt.show()

examples/tests/backend_driver.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
pylab=os.path.join('..', 'pylab_examples'),
4646
api=os.path.join('..', 'api'),
4747
units=os.path.join('..', 'units'),
48-
mplot3d=os.path.join('..', 'mplot3d'))
48+
mplot3d=os.path.join('..', 'mplot3d'),
49+
colors=os.path.join('..', 'color'))
4950

5051

5152
# files in each dir
@@ -66,6 +67,7 @@
6667
]
6768

6869
files['colors'] = [
70+
'color_cycle_default.py',
6971
'color_cycle_demo.py',
7072
]
7173

0 commit comments

Comments
 (0)