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 matplotlib.pyplot as plt fig = plt.figure() # 在这个画布中...
https://matplotlib.org/api/_as_gen/matplotlib.pyplot.subplots_adjust.html 在子图坐标轴ax4中画出sin(x)的曲线 添加以下代码 # add a red subplot that share the x-axis with ax1 ax4 = fig.add_subplot(324, sharex=ax1, facecolor='red') # row = 3, col = 2, index = 4 # 在坐标轴ax4中...
matplotlib.pyplot.figure():创建一个心的图形窗口或图表对象,以便在其上进行绘图操作 matplotlib.pyplot.rcParams:获取或设置全局绘图参数的默认值,如图形尺寸、字体大小、线条样式等 matplotlib.pyplot.scatter():绘制散点图 matplotlib.pyplot.subplot():用于在当前图形窗口中创建一个子图,并定位该子图在整个图形窗口中...
add_subplot(nrows, ncols, index):创建一个nrows行ncols列的子图网格,指定index号所在的子图进行绘制。 add_subplot(ax):在给定的轴对象ax上绘制子图。下面通过一些实例来展示add_subplot方法的使用方法和技巧。实例1:使用add_subplot创建2x2的子图网格 import matplotlib.pyplot as plt import numpy as np # 生...
fig.add_subplot(pos):其中 pos 是一个三位整数,表示子图的位置(行、列、索引)。 3. 示例代码 下面是一个简单的示例,展示了如何使用 add_subplot 创建一个 2x2 的子图网格,并在每个子图中绘制不同的图形。 python import matplotlib.pyplot as plt import numpy as np # 创建数据 x = np.linspace(0, ...
1、matplotlib.pyplot api 方式添加子图 2、面向对象方式添加子图 3、matplotlib.pyplot add_subplot方式添加子图 4、matplotlib.gridspec.GridSpec方式添加子图 5、子图中绘制子图 6、任意位置绘制子图(plt.axes 关于pyplot和面向对象两种绘图方式可参考之前文章:matplotlib.pyplot api verus matplotlib object-oriented ...
注意,pyplot的方式中plt.subplot()参数和面向对象中的add_subplot()参数和含义都相同。 使用面向对象的方式 #!/usr/bin/python#coding: utf-8import numpy as np import matplotlib.pyplot as plt x = np.arange(0,100) fig = plt.figure() ax1 = fig.add_subplot(221) ...
第一个参数和第二个参数可以不一样。 importmatplotlib.pyplotasplt x = [1,2,3,4,5] y = [1,4,9,16,20] fig = plt.figure() fig.add_subplot(111) plt.scatter(x, y) plt.show()
1.subplot()函数 '''1.subplot()函数'''importmatplotlib.pyplotaspltax1=plt.subplot(212)#2*1,第2行ax2=plt.subplot(221)#2*2,第1张ax3=plt.subplot(222)#2*2,第2张 2.add_subplot()函数 add_subplot()与subplot()不同之处在于,add_subplot()需要提前创建画布,在已有画布上进行绘制。