matplotlib.pyplot.subplots

 
分别将example1-7的注释去掉并运行,可以看到结果
 
import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 2*np.pi, 400)
y = np.sin(x**2)

## example1
# # Create just a figure and only one subplot
# fig, ax = plt.subplots()
# ax.plot(x, y)
# ax.set_title('Simple plot')

##example 2
# # Create two subplots and unpack the output array immediately
# f, (ax1, ax2) = plt.subplots(1, 2, sharey=True)
# ax1.plot(x, y)
# ax1.set_title('Sharing Y axis')
# ax2.scatter(x, y)

##example 3
# # Create four polar axes and access them through the returned array
# fig, axs = plt.subplots(2, 2, subplot_kw=dict(polar=True))
# axs[0, 0].plot(x, y)
# axs[1, 1].scatter(x, y)

##example 4
# # Share a X axis with each column of subplots
# plt.subplots(2, 2, sharex='col')

##example 5
# # Share a Y axis with each row of subplots
# plt.subplots(2, 2, sharey='row')

##example 6
# Share both X and Y axes with all subplots
# plt.subplots(2, 2, sharex='all', sharey='all')
##example as 6
# # Note that this is the same as
# plt.subplots(2, 2, sharex=True, sharey=True)

##example 7
# Create figure number 10 with a single subplot
# and clears it if it already exists.
# fig, ax = plt.subplots(num=10, clear=True)

plt.show()

posted on 2020-03-20 10:48  风中狂笑  阅读(549)  评论(0编辑  收藏  举报

导航