Zhiguang Huo (Caleb)
Monday Nov 28th, 2022
A toy example
Single figure
Multiple subfigures
Single figure
Multiple subfigures
## array([[<AxesSubplot: >, <AxesSubplot: >],
## [<AxesSubplot: >, <AxesSubplot: >]], dtype=object)
fig, axes = plt.subplots(2,3,sharex=True, sharey=True)
axes[0,0].plot(data_cumsum, marker = "o")
axes[0,1].plot(data_cumsum, marker = "v")
axes[0,2].plot(data_cumsum, marker = "^")
axes[1,0].plot(data_cumsum, marker = "D")
axes[1,1].plot(data_cumsum, marker = "X")
axes[1,2].plot(data_cumsum, marker = "s")
plt.show()
also works for y axis (set_yticks, set_xticklabels, etc)
df = pd.DataFrame({"names":['A', 'B', 'C'], "values":[1,2,3]})
plt.figure(figsize=(9, 3))
plt.subplot(131)
plt.bar("names", "values", data=df)
## <BarContainer object of 3 artists>
pd1 = pd.DataFrame(np.random.rand(4,3), index = list("abcd"), columns = ["Florida", "Texax", "Utah"])
pd1.columns.name="Columns"
pd1.index.name="States"
fig = plt.figure(figsize=(6, 3))
ax = fig.add_subplot(1,2,1)
pd1.plot.bar(ax = ax)
bx = fig.add_subplot(1,2,2)
pd1.plot.barh(ax = bx, stacked=True)
plt.show()
## (array([ 1., 1., 1., 2., 3., 5., 14., 9., 10., 9., 13., 12., 5.,
## 5., 6., 1., 0., 1., 1., 1.]), array([-2.8231562 , -2.53336371, -2.24357122, -1.95377874, -1.66398625,
## -1.37419376, -1.08440128, -0.79460879, -0.50481631, -0.21502382,
## 0.07476867, 0.36456115, 0.65435364, 0.94414612, 1.23393861,
## 1.5237311 , 1.81352358, 2.10331607, 2.39310855, 2.68290104,
## 2.97269353]), <BarContainer object of 20 artists>)
## <string>:1: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`). Consider using `matplotlib.pyplot.close()`.
np.random.seed(32608)
plt.subplot(211)
plt.imshow(np.random.random((100, 100)))
plt.subplot(212)
plt.imshow(np.random.random((100, 100)))
cax = plt.axes([0.85, 0.1, 0.075, 0.8])
plt.colorbar(cax=cax)
## <matplotlib.colorbar.Colorbar object at 0x13d337700>