plt.plot(range(12)) # 创建第二个有着黄色背景的子图 plt.subplot(212, facecolor='y') # creates 2nd subplot with yellow background plt.plot([4,6,8]) plt.show() 1. 2. 3. 4. 5. 6. 7. 8. 9. 显示结果如下: 画布中的add_subplot()函数不
ax2=fig.add_subplot(322, frameon=False) # row = 3, col = 2, index = 2 # add a polar subplot fig.add_subplot(323, projection='polar') # row = 3, col = 2, index = 3 # add a red subplot that share the x-axis with ax1 fig.add_subplot(324, sharex=ax1, facecolor='red')...
使用面向对象接口时,需要显式地创建一个Figure对象和一个或多个Axes对象,并在指定的Axes对象上调用plot()方法进行绘图。ax.plot()适合更为复杂的绘图需求,并且具有更高的灵活性。 三、使用add_subplot add_subplot()函数用于在图形中添加子图,其基本语法如下所示: fig.add_subplot(nrows, ncols, index) 其中,f...
plot(x, y) axs[0, 0].set_title('Subplot (1,1)') axs[0, 1].plot(x, -y, 'tab:orange') axs[0, 1].set_title('Subplot (1,2)') axs[1, 0].plot(x, np.cos(x), 'tab:green') axs[1, 0].set_title('Subplot (2,1)') axs[1, 1].plot(x, np.exp(x), 'tab:red')...
plt.figure创建一张画布,使用plt.subplot函数或其他的作图函数在这张画布上作一幅图。如果要作多幅并列的图,使用plt.add_subplot函数。 plt.rcParams['font.family'] = 'Microsoft YaHei' fig1 = plt.figure(figsize=[8,7]) # ax1 = fig1.add_subplot(121) #1行2列,第1幅图 ax1.plot(x, y1) #pl...
3、matplotlib.pyplot add_subplot方式添加子图 my_dpi=96fig=plt.figure(figsize=(480/my_dpi,480/my_dpi),dpi=my_dpi)fig.add_subplot(221)plt.plot([1,2,3])fig.add_subplot(222)plt.bar([1,2,3],[4,5,6])plt.title('fig.add_subplot(222)')fig.add_subplot(223)plt.plot([1,2,3])fig...
ax1.plot(x, y1, label='sin(x)') ax1.legend() ax2 = fig.add_subplot(2, 2, 2) #在 2x2 网格中的第二个位置添加子图 ax2.plot(x, y2, label='cos(x)', color='orange') ax2.legend() ax3 = fig.add_subplot(2, 2, 3) #在 2x2 网格中的第三个位置添加子图 ax3.plot(x, y3...
f.add_subplot(224) sns.violinplot('dataset','y',data = data, palette = 'husl') plt.xlabel('(d)') plt.tight_layout() plt.show() 由图(c)可以看出第IV组的大部分的数据的x集中在8一点,而y分布与6周围,可以知道y和x的相关性很小,通过(a) (b)我们也可以看到离群点, ...
importmatplotlib.pyplotaspltimportnumpyasnp# 创建数据x=np.linspace(0,10,100)y1=np.sin(x)y2=np.cos(x)y3=np.sin(x)*np.cos(x)y4=np.tan(x)# 创建图形对象fig=plt.figure(figsize=(10,8))# 添加第一个子图ax1=fig.add_subplot(221)ax1.plot(x,y1,label='sin(x)',color='b')ax1.set...
add_suplot()方法语法 add_subplot(self, *args, **kwargs) 1. add_subplot()方法,“向figure添加一个Axes作为一subplot布局的一部分。” 要调用add_subplot()方法,有4种签名形式: add_subplot(nrows, ncols, index, **kwargs) add_subplot(pos, **kwargs) ...