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

Skip to content

Commit 30fd3d1

Browse files
authored
Merge pull request #21226 from timhoffm/examples-colors
DOC: Adapt some colors in examples
2 parents 5725b91 + 3dd8eee commit 30fd3d1

File tree

4 files changed

+28
-24
lines changed

4 files changed

+28
-24
lines changed

examples/lines_bars_and_markers/fill_between_alpha.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
import matplotlib.cbook as cbook
1818

1919

20-
# Fixing random state for reproducibility
21-
np.random.seed(19680801)
22-
2320
# load up some sample financial data
2421
r = (cbook.get_sample_data('goog.npz', np_load=True)['price_data']
2522
.view(np.recarray))
@@ -29,7 +26,7 @@
2926
pricemin = r.close.min()
3027

3128
ax1.plot(r.date, r.close, lw=2)
32-
ax2.fill_between(r.date, pricemin, r.close, facecolor='blue', alpha=0.5)
29+
ax2.fill_between(r.date, pricemin, r.close, alpha=0.7)
3330

3431
for ax in ax1, ax2:
3532
ax.grid(True)
@@ -52,16 +49,19 @@
5249
#
5350
# Our next example computes two populations of random walkers with a
5451
# different mean and standard deviation of the normal distributions from
55-
# which the steps are drawn. We use shared regions to plot +/- one
52+
# which the steps are drawn. We use filled regions to plot +/- one
5653
# standard deviation of the mean position of the population. Here the
5754
# alpha channel is useful, not just aesthetic.
5855

56+
# Fixing random state for reproducibility
57+
np.random.seed(19680801)
58+
5959
Nsteps, Nwalkers = 100, 250
6060
t = np.arange(Nsteps)
6161

6262
# an (Nsteps x Nwalkers) array of random walk steps
63-
S1 = 0.002 + 0.01*np.random.randn(Nsteps, Nwalkers)
64-
S2 = 0.004 + 0.02*np.random.randn(Nsteps, Nwalkers)
63+
S1 = 0.004 + 0.02*np.random.randn(Nsteps, Nwalkers)
64+
S2 = 0.002 + 0.01*np.random.randn(Nsteps, Nwalkers)
6565

6666
# an (Nsteps x Nwalkers) array of random walker positions
6767
X1 = S1.cumsum(axis=0)
@@ -77,10 +77,10 @@
7777

7878
# plot it!
7979
fig, ax = plt.subplots(1)
80-
ax.plot(t, mu1, lw=2, label='mean population 1', color='blue')
81-
ax.plot(t, mu2, lw=2, label='mean population 2', color='yellow')
82-
ax.fill_between(t, mu1+sigma1, mu1-sigma1, facecolor='blue', alpha=0.5)
83-
ax.fill_between(t, mu2+sigma2, mu2-sigma2, facecolor='yellow', alpha=0.5)
80+
ax.plot(t, mu1, lw=2, label='mean population 1')
81+
ax.plot(t, mu2, lw=2, label='mean population 2')
82+
ax.fill_between(t, mu1+sigma1, mu1-sigma1, facecolor='C0', alpha=0.4)
83+
ax.fill_between(t, mu2+sigma2, mu2-sigma2, facecolor='C1', alpha=0.4)
8484
ax.set_title(r'random walkers empirical $\mu$ and $\pm \sigma$ interval')
8585
ax.legend(loc='upper left')
8686
ax.set_xlabel('num steps')
@@ -93,11 +93,14 @@
9393
# as the x, ymin and ymax arguments, and only fills in the region where
9494
# the boolean mask is True. In the example below, we simulate a single
9595
# random walker and compute the analytic mean and standard deviation of
96-
# the population positions. The population mean is shown as the black
97-
# dashed line, and the plus/minus one sigma deviation from the mean is
98-
# shown as the yellow filled region. We use the where mask
99-
# ``X > upper_bound`` to find the region where the walker is above the one
100-
# sigma boundary, and shade that region blue.
96+
# the population positions. The population mean is shown as the dashed
97+
# line, and the plus/minus one sigma deviation from the mean is shown
98+
# as the filled region. We use the where mask ``X > upper_bound`` to
99+
# find the region where the walker is outside the one sigma boundary,
100+
# and shade that region red.
101+
102+
# Fixing random state for reproducibility
103+
np.random.seed(1)
101104

102105
Nsteps = 500
103106
t = np.arange(Nsteps)
@@ -114,16 +117,16 @@
114117
upper_bound = mu*t + sigma*np.sqrt(t)
115118

116119
fig, ax = plt.subplots(1)
117-
ax.plot(t, X, lw=2, label='walker position', color='blue')
118-
ax.plot(t, mu*t, lw=1, label='population mean', color='black', ls='--')
119-
ax.fill_between(t, lower_bound, upper_bound, facecolor='yellow', alpha=0.5,
120+
ax.plot(t, X, lw=2, label='walker position')
121+
ax.plot(t, mu*t, lw=1, label='population mean', color='C0', ls='--')
122+
ax.fill_between(t, lower_bound, upper_bound, facecolor='C0', alpha=0.4,
120123
label='1 sigma range')
121124
ax.legend(loc='upper left')
122125

123126
# here we use the where argument to only fill the region where the
124127
# walker is above the population 1 sigma boundary
125-
ax.fill_between(t, upper_bound, X, where=X > upper_bound, facecolor='blue',
126-
alpha=0.5)
128+
ax.fill_between(t, upper_bound, X, where=X > upper_bound, fc='red', alpha=0.4)
129+
ax.fill_between(t, lower_bound, X, where=X < lower_bound, fc='red', alpha=0.4)
127130
ax.set_xlabel('num steps')
128131
ax.set_ylabel('position')
129132
ax.grid()

examples/lines_bars_and_markers/filled_step.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def filled_hist(ax, edges, values, bottoms=None, orientation='v',
5353
"not {o}".format(o=orientation))
5454

5555
kwargs.setdefault('step', 'post')
56+
kwargs.setdefault('alpha', 0.7)
5657
edges = np.asarray(edges)
5758
values = np.asarray(values)
5859
if len(edges) - 1 != len(values):

examples/lines_bars_and_markers/gradient_bar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ def gradient_bar(ax, x, y, width=0.5, bottom=0):
7070
ax.set(xlim=xlim, ylim=ylim, autoscale_on=False)
7171

7272
# background image
73-
gradient_image(ax, direction=0, extent=(0, 1, 0, 1), transform=ax.transAxes,
74-
cmap=plt.cm.Oranges, cmap_range=(0.1, 0.6))
73+
gradient_image(ax, direction=1, extent=(0, 1, 0, 1), transform=ax.transAxes,
74+
cmap=plt.cm.RdYlGn, cmap_range=(0.2, 0.8), alpha=0.5)
7575

7676
N = 10
7777
x = np.arange(N) + 0.15

examples/lines_bars_and_markers/stackplot_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
fig, ax = plt.subplots()
3131
ax.stackplot(year, population_by_continent.values(),
32-
labels=population_by_continent.keys())
32+
labels=population_by_continent.keys(), alpha=0.8)
3333
ax.legend(loc='upper left')
3434
ax.set_title('World population')
3535
ax.set_xlabel('Year')

0 commit comments

Comments
 (0)