add_subplot(2, 1, 2) # 2行1列的第2个子图 ax2.plot(x, y2) ax2.set_title('cos(x)') # 显示figure对象 plt.show() 在上面的示例代码中,我们首先创建了一个figure对象。然后使用add_subplot()方法添加了两个子图,一个用于绘制sin(x)函数,另一个用于绘制cos(x)函数。每个子图都有自己的坐标轴...
x=np.linspace(0,10,100)y=np.sin(x)plt.subplot(221)plt.plot(x,y)plt.title('Subplot 221 - how2matplotlib.com')plt.subplot(222)plt.plot(x,y**2)plt.title('Subplot 222 - how2matplotlib.com')plt.subplot(223)plt.plot(x,y**3)plt.title('Subplot 223 - how2matplotlib.com')plt.subpl...
import matplotlib.pyplot as plt import numpy as np # 创建数据 x = np.linspace(0, 2 * np.pi, 100) y1 = np.sin(x) y2 = np.cos(x) y3 = np.sin(x) + np.cos(x) y4 = np.sin(x) - np.cos(x) # 创建一个图形对象 fig = plt.figure() # 添加子图 ax1 = fig.add_subplot(...
add_subplot(ax) 2.代码实例 以下代码出自add_subplot的说明,我改了个row的参数,加了点东西,方便大家看效果 #! /usr/bin/env python # -*- coding: utf-8 -*- import matplotlib.pyplot as plt fig=plt.figure('subplot demo') # 图像标题为'subplot demo',否则默认为'Figure 1' # 接下来是在一个...
「方式二:通过figure的add_subplot」 代码语言:javascript 代码运行次数:0 运行 AI代码解释 importnumpyasnpimportpandasaspdimportmatplotlib.pyplotasplt%matplotlib inline fig=plt.figure()# 画第1个图:折线图 x=np.arange(1,100)ax1=fig.add_subplot(221)ax1.plot(x,x*x)# 画第2个图:散点图 ...
「方式二:通过figure的add_subplot」 importnumpyasnp importpandasaspd importmatplotlib.pyplotasplt %matplotlibinline fig=plt.figure() #画第1个图:折线图 x=np.arange(1,100) ax1=fig.add_subplot(221) ax1.plot(x,x*x) #画第2个图:散点图 ...
导入模块pyplot,并给它指定别名plt,以免反复输入pyplot。在模块pyplot中包含很多用于生产图表的函数。 将绘制的直线坐标传递给函数plot()。 通过函数plt.show()打开Matplotlib查看器,显示绘制的图形。 【示例】根据两点绘制一条线 代码语言:javascript 代码运行次数:0 ...
第一种常见画法:用 fig 画出多个 axes 子图(fig.add_subplot(221)) 第二种常见画法:plt.subplots(nrows, ncols) + axes[0, 0] 第三种细致画法:一个Figure,画多个Axes(fig1.add_axes(传入axes的具体位置) ) 第四种常见画法:plt.subplot() 画出多个 figure ...
from matplotlib import pyplot as plt #创建图形对象 fig = plt.figure() 1. 2. 3. 该函数的参数值,如下所示: 下面使用 figure() 创建一个空白画布 AI检测代码解析 fig = plt.figure() 1. 我们使用 add_axes() 将 axes 轴域添加到画布中。如下所示: ...