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

Skip to content

Commit 1e047a4

Browse files
committed
Clean up bar_demo2.py
1 parent f885639 commit 1e047a4

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
@@ -11,26 +11,21 @@
1111
from basic_units import cm, inch
1212
import matplotlib.pyplot as plt
1313

14-
1514
cms = cm * np.arange(0, 10, 2)
16-
bottom = 0*cm
17-
width = 0.8*cm
15+
bottom = 0 * cm
16+
width = 0.8 * cm
1817

19-
fig = plt.figure()
18+
fig, axs = plt.subplots(2, 2)
2019

21-
ax1 = fig.add_subplot(2, 2, 1)
22-
ax1.bar(cms, cms, bottom=bottom)
20+
axs[0, 0].bar(cms, cms, bottom=bottom)
2321

24-
ax2 = fig.add_subplot(2, 2, 2)
25-
ax2.bar(cms, cms, bottom=bottom, width=width, xunits=cm, yunits=inch)
22+
axs[0, 1].bar(cms, cms, bottom=bottom, width=width, xunits=cm, yunits=inch)
2623

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

31-
ax4 = fig.add_subplot(2, 2, 4)
32-
ax4.bar(cms, cms, bottom=bottom, width=width, xunits=inch, yunits=inch)
33-
#fig.savefig('simple_conversion_plot.png')
34-
ax4.set_xlim(2*cm, 6*cm) # cm are converted to inches
27+
axs[1, 1].bar(cms, cms, bottom=bottom, width=width, xunits=inch, yunits=inch)
28+
axs[1, 1].set_xlim(2 * cm, 6 * cm) # cm are converted to inches
3529

30+
fig.tight_layout()
3631
plt.show()

0 commit comments

Comments
 (0)