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

Skip to content

Commit e9a5a2b

Browse files
QuLogicdstansby
authored andcommitted
Merge pull request #8256 from dstansby/bar_demo2-clean
[DOC] Clean up bar_demo2
1 parent 224deca commit e9a5a2b

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

examples/units/bar_demo2.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,21 @@
1515
from basic_units import cm, inch
1616
import matplotlib.pyplot as plt
1717

18-
1918
cms = cm * np.arange(0, 10, 2)
20-
bottom = 0*cm
21-
width = 0.8*cm
19+
bottom = 0 * cm
20+
width = 0.8 * cm
2221

23-
fig = plt.figure()
22+
fig, axs = plt.subplots(2, 2)
2423

25-
ax1 = fig.add_subplot(2, 2, 1)
26-
ax1.bar(cms, cms, bottom=bottom)
24+
axs[0, 0].bar(cms, cms, bottom=bottom)
2725

28-
ax2 = fig.add_subplot(2, 2, 2)
29-
ax2.bar(cms, cms, bottom=bottom, width=width, xunits=cm, yunits=inch)
26+
axs[0, 1].bar(cms, cms, bottom=bottom, width=width, xunits=cm, yunits=inch)
3027

31-
ax3 = fig.add_subplot(2, 2, 3)
32-
ax3.bar(cms, cms, bottom=bottom, width=width, xunits=inch, yunits=cm)
33-
ax3.set_xlim(2, 6) # scalars are interpreted in current units
28+
axs[1, 0].bar(cms, cms, bottom=bottom, width=width, xunits=inch, yunits=cm)
29+
axs[1, 0].set_xlim(2, 6) # scalars are interpreted in current units
3430

35-
ax4 = fig.add_subplot(2, 2, 4)
36-
ax4.bar(cms, cms, bottom=bottom, width=width, xunits=inch, yunits=inch)
37-
# fig.savefig('simple_conversion_plot.png')
38-
ax4.set_xlim(2*cm, 6*cm) # cm are converted to inches
31+
axs[1, 1].bar(cms, cms, bottom=bottom, width=width, xunits=inch, yunits=inch)
32+
axs[1, 1].set_xlim(2 * cm, 6 * cm) # cm are converted to inches
3933

34+
fig.tight_layout()
4035
plt.show()

0 commit comments

Comments
 (0)