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

Skip to content

Commit 30a85ba

Browse files
committed
Clean up and move color_cycle demo
1 parent 405cbc5 commit 30a85ba

File tree

4 files changed

+36
-28
lines changed

4 files changed

+36
-28
lines changed

doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
'statistics',
8989
'images_contours_and_fields',
9090
'pie_and_polar_charts',
91+
'color',
9192
'text_labels_and_annotations',
9293
'ticks_and_spines',
9394
'subplots_axes_and_figures',

doc/sphinxext/gen_gallery.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
'subplots_axes_and_figures': 'Subplots, axes, and figures',
2323
'specialty_plots': 'Specialty plots',
2424
'showcase': 'Showcase',
25+
'color': 'Color',
2526
'api': 'API',
2627
}
2728

examples/api/color_cycle.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

examples/color/color_cycle_demo.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
Demo of custom color-cycle settings to control colors for multi-line plots.
3+
4+
This example demonstrates two different APIs:
5+
6+
1. Setting the default rc-parameter specifying the color cycle.
7+
This affects all subsequent plots.
8+
2. Setting the color cycle for a specific axes. This only affects a single
9+
axes.
10+
"""
11+
import numpy as np
12+
import matplotlib.pyplot as plt
13+
14+
x = np.linspace(0, 2 * np.pi)
15+
offsets = np.linspace(0, 2*np.pi, 4, endpoint=False)
16+
# Create array with shifted-sine curve along each column
17+
yy = np.transpose([np.sin(x + phi) for phi in offsets])
18+
19+
plt.rc('lines', linewidth=4)
20+
fig, (ax0, ax1) = plt.subplots(nrows=2)
21+
22+
plt.rc('axes', color_cycle=['r', 'g', 'b', 'y'])
23+
ax0.plot(yy)
24+
ax0.set_title('Set default color cycle to rgby')
25+
26+
ax1.set_color_cycle(['c', 'm', 'y', 'k'])
27+
ax1.plot(yy)
28+
ax1.set_title('Set axes color cycle to cmyk')
29+
30+
# Tweak spacing between subplots to prevent labels from overlapping
31+
plt.subplots_adjust(hspace=0.3)
32+
plt.show()
33+
34+

0 commit comments

Comments
 (0)