subplots() # 创建第二个y轴ax2,共享ax1的x轴 ax2 = ax1.twinx() #在ax1上绘制x和y1的关系,线条为绿色实线 ax1.plot(x, y1, 'g-') # green, solid line # 设置ax1的x轴和y轴标签 ax1.set_xlabel('X data') ax1.set_ylabel('Y1 data', color='g') #在ax2上绘制x和y2的...
plt.rcParams['ytick.direction'] = 'in' # 将y轴的刻度方向设置向内 x = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0] y = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0] fig, ax1 = plt.subplots() ax1.plot(x, y, "b--") ax1.plot(x, y[::-...
fig.suptitle('Vertically stacked subplots') axs[0].plot(x, y) axs[1].plot(x, -y) 1. 2. 3. 4. 当然如果你的子图比较少,可以考虑用元组接收axes对象: fig, (ax1, ax2) = plt.subplots(2) fig.suptitle('Vertically stacked subplots') ax1.plot(x, y) ax2.plot(x, -y) 1. 2. 3. ...
importmatplotlib.pyplotaspltimportnumpyasnp# 创建2x2的子图布局fig,axs=plt.subplots(2,2,figsize=(10,8))# 生成一些示例数据x=np.linspace(0,10,100)y1=np.sin(x)y2=np.cos(x)y3=np.exp(-x/10)y4=x**2# 在每个子图中绘制不同的函数axs[0,0].plot(x,y1)axs[0,0].set_title('Sine Func...
plt.subplots提供了多个参数来调整子图的布局: 3.1 figsize figsize参数用于设置整个图形的大小,单位为英寸。例如: importmatplotlib.pyplotaspltimportnumpyasnp fig,axs=plt.subplots(2,2,figsize=(12,10))x=np.linspace(0,2*np.pi,100)foriinrange(2):forjinrange(2):axs[i,j].plot(x,np.sin(x+i*np...
ax.plot(squares) #传递表格中需要绘制的数据 plt.show() subplots()函数: subplots(nrows=1, ncols=1, sharex=False,sharey=False, squeeze=True, subplot_kw=None, gridspec_kw=None, ** fig_kw) ——详见网址—— nrows,ncols参数:整数类型,可选项,默认均为1.nrows是设置横向网格(表格数量)ncols是...
subplot在plotNum指定的区域中创建一个轴对象. 如果新创建的轴和之前创建的轴重叠的话,之前的轴将被删除. 二、参数说明 1,subplots()参数 matplotlib.pyplot.subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, subplot_kw=None, gridspec_kw=None, **fig_kw) ...
4. 示例四,绘制多幅图像 importnumpyasnpimportmatplotlib.pyplotasplt aa=range (1,11)bb=np.random.rand(10)figure=plt.figure(figsize=(8,4),facecolor="red")axes1=plt.subplot (2,2,1)axes1.plot(aa,bb)axes2=plt.subplot(2,2,2)axes2.bar(aa,bb)axes3=plt.subplot(2,1,2)axes3.plot(aa...
axs = inner_grid.subplots()# Create all subplots for the inner grid.for (c, d), ax in np.ndenumerate(axs): ax.plot(*squiggle_xy(a +1,b+1, c +1, d +1)) ax.set(xticks=[], yticks=[])# show only the outside spinesfor ax in fig.get_axes(): ...
05 fig, axes_list = plt.subplots(2, 2) 06 #构造X轴和Y轴数据 07 x = np.linspace(0, 2 * np.pi, 400) 08 y = np.sin(x**2) 09 #在第1行第1列的子图中绘图 10 axes_list[1, 1].plot(x, y) 11 plt.show() 【运行结果】 ...