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()函数不会覆盖现有的图,看下面实例: import matplotli...
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')...
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...
ax4 = fig.add_subplot(224) ax4.plot(x, np.log(x)) plt.show() AI代码助手复制代码 pyplot的方式 #!/usr/bin/python#coding: utf-8import numpy as np import matplotlib.pyplot as plt x = np.arange(0,100) plt.subplot(221) plt.plot(x, x) ...
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...
- subplot_kw:字典,用于设置创建子图时的关键字参数。 这里是一个简单的示例,演示如何使用add_subplot()函数创建一个包含多个子图的图形: import matplotlib.pyplot as plt #创建一个包含2行2列的子图网格 fig, axes = plt.subplots(nrows=2, ncols=2) #在不同的子图中绘制不同的内容 axes[0, 0].plot(...
add_subplot(1, 1, 1) ax.plot(np.random.randn(1000).cumsum()) plt.show() 为了改变x轴刻度,使用set_xticks和set_xticklabels方法。前者表明刻度标注的范围,后者设置刻度标签的内容: fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ax.plot(np.random.randn(1000).cumsum()) ticks = ax....
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)我们也可以看到离群点, ...