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

Skip to content

Commit 36d563b

Browse files
committed
Merge pull request #6505 from tacaswell/examples
Examples
2 parents 59e0ab9 + b3c21d3 commit 36d563b

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

examples/color/named_colors.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
ncols = 4
2828
nrows = int(np.ceil(1. * n / ncols))
2929

30-
fig, ax = plt.subplots()
30+
fig, ax = plt.subplots(figsize=(8, 5))
3131

3232
X, Y = fig.get_dpi() * fig.get_size_inches()
3333

@@ -49,10 +49,6 @@
4949
horizontalalignment='left',
5050
verticalalignment='center')
5151

52-
# Add extra black line a little bit thicker to make
53-
# clear colors more visible.
54-
ax.hlines(
55-
y, xi_line, xf_line, color='black', linewidth=(h * 0.7))
5652
ax.hlines(
5753
y + h * 0.1, xi_line, xf_line, color=colors[name], linewidth=(h * 0.6))
5854

examples/pylab_examples/csd_demo.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
import numpy as np
66
import matplotlib.pyplot as plt
77

8+
9+
fig, (ax1, ax2) = plt.subplots(2, 1)
810
# make a little extra space between the subplots
9-
plt.subplots_adjust(wspace=0.5)
11+
fig.subplots_adjust(hspace=0.5)
1012

1113
dt = 0.01
1214
t = np.arange(0, 30, dt)
@@ -21,14 +23,12 @@
2123
s1 = 0.01*np.sin(2*np.pi*10*t) + cnse1
2224
s2 = 0.01*np.sin(2*np.pi*10*t) + cnse2
2325

24-
plt.subplot(211)
25-
plt.plot(t, s1, t, s2)
26-
plt.xlim(0, 5)
27-
plt.xlabel('time')
28-
plt.ylabel('s1 and s2')
29-
plt.grid(True)
26+
ax1.plot(t, s1, t, s2)
27+
ax1.set_xlim(0, 5)
28+
ax1.set_xlabel('time')
29+
ax1.set_ylabel('s1 and s2')
30+
ax1.grid(True)
3031

31-
plt.subplot(212)
32-
cxy, f = plt.csd(s1, s2, 256, 1./dt)
33-
plt.ylabel('CSD (db)')
32+
cxy, f = ax2.csd(s1, s2, 256, 1./dt)
33+
ax2.set_ylabel('CSD (db)')
3434
plt.show()

examples/showcase/bachelors_degrees_by_gender.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727
ax.get_xaxis().tick_bottom()
2828
ax.get_yaxis().tick_left()
2929

30+
fig.subplots_adjust(left=.06, right=.75, bottom=.02, top=.94)
3031
# Limit the range of the plot to only where the data is.
3132
# Avoid unnecessary whitespace.
32-
plt.xlim(1968.5, 2011.1)
33-
plt.ylim(-0.25, 90)
33+
ax.set_xlim(1968.5, 2011.1)
34+
ax.set_ylim(-0.25, 90)
35+
ax.get_xaxis().get_major_formatter().set_useOffset(False)
3436

3537
# Make sure your axis ticks are large enough to be easily read.
3638
# You don't want your viewers squinting to read your plot.
@@ -91,10 +93,10 @@
9193

9294
# Note that if the title is descriptive enough, it is unnecessary to include
9395
# axis labels; they are self-evident, in this plot's case.
94-
plt.title('Percentage of Bachelor\'s degrees conferred to women in '
95-
'the U.S.A. by major (1970-2011)\n', fontsize=18, ha='center')
96+
fig.suptitle('Percentage of Bachelor\'s degrees conferred to women in '
97+
'the U.S.A. by major (1970-2011)\n', fontsize=18, ha='center')
9698

9799
# Finally, save the figure as a PNG.
98100
# You can also save it as a PDF, JPEG, etc.
99101
# Just change the file extension in this call.
100-
plt.savefig('percent-bachelors-degrees-women-usa.png', bbox_inches='tight')
102+
# plt.savefig('percent-bachelors-degrees-women-usa.png', bbox_inches='tight')

0 commit comments

Comments
 (0)