在这个例子中,我们创建了一个12×10英寸的图形,包含2×2的子图布局。 3.2 sharex 和 sharey sharex 和 sharey 参数允许子图共享 x 轴或 y 轴。这在比较具有相同范围的多个图表时非常有用: importmatplotlib.pyplotaspltimportnumpyasnp fig,axs=plt.subplots(2,2,figsize=(10,8),sharex=True,sharey=True...
importmatplotlib.pyplotaspltimportnumpyasnp# 创建一些测试数据x = np.linspace(0,2*np.pi,400) y = np.sin(x**2) f, (ax1, ax2) = plt.subplots(1,2, sharey=True) ax1.plot(x, y) ax1.set_title('Sharing Y axis') ax2.scatter(x, y) plt.show() 绘制图形如下...
ax1.set_title('Sharing Y axis') ax2.scatter(x, y)# Create four polar axes and access them through the returned arrayfig, axs = plt.subplots(2,2, subplot_kw=dict(projection="polar")) axs[0,0].plot(x, y) axs[ 1,1].scatter(x, y)# Share a X axis with each column ofsubplots...
# 创建两个子图,并且共享y轴 f, (ax1,ax2)=plt.subplots( 1, 2,sharey= True) ax1.plot(x,y) ax1.set_title( 'Sharing Y axis') ax2.scatter(x,y) 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28...
ax2.scatter(x, y)# Create four polar Axes and access them through the returned arrayaxes = fig.subplots(2,2, subplot_kw=dict(projection='polar')) axes[0,0].plot(x, y) axes[ 1,1].scatter(x, y)# Share an X-axis with each column ofsubplotsfig.subplots( ...
(x,y2)axs[0,1].set_title('Cosine - how2matplotlib.com')axs[1,0].plot(x,y3)axs[1,0].set_title('Tangent - how2matplotlib.com')axs[1,1].plot(x,y4)axs[1,1].set_title('Sine * Cosine - how2matplotlib.com')# 为整个图形设置X轴和Y轴标签fig.text(0.5,0.04,'X axis',ha='...
y = np.sin(x**2) # 创建一个画像和子图 -- 图2 fig, ax = plt.subplots() ax.plot(x, y) ax.set_title('Simple plot') # 创建两个子图 -- 图3 f, (ax1, ax2) = plt.subplots(1, 2, sharey=True) ax1.plot(x, y) ax1.set_title('Sharing Y axis') ...
y = np.sin(x **2) plt.close('all') 只有一个图形和一个子图 f, ax = plt.subplots() ax.plot(x, y) ax.set_title('Simple plot') 两个子图,轴数组是一维的。 f, axarr = plt.subplots(2, sharex=True) f.suptitle('Sharing X axis') ...
>>> ax.plot(x, y) >>> ax.set_title('Simple plot') 创建两个subplot >>> f, (ax1, ax2) = plt.subplots(1, 2, sharey=True) >>> ax1.plot(x, y) >>> ax1.set_title('Sharing Y axis') >>> ax2.scatter(x, y) Creates four polar axes, and accesses them through the returne...
# 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') ...