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)函数。每个子图都有自己的坐标轴
fig = plt.figure(figsize=(10, 6))```在图形对象上,我们使用add\_subplot方法添加两个子图。第一个子图位于2行1列的第1个位置,并绘制正弦波形:```python ax1 = fig.add_subplot(2, 1, 1)ax1.plot(x, y1)ax1.set_title('Sine Wave')```同样地,第二个子图位于2行1列的第2个位置,并绘制...
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' # 接下来是在一个...
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...
「方式二:通过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个图:散点图 ...
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(...
第一种常见画法:用 fig 画出多个 axes 子图(fig.add_subplot(221)) 第二种常见画法:plt.subplots(nrows, ncols) + axes[0, 0] 第三种细致画法:一个Figure,画多个Axes(fig1.add_axes(传入axes的具体位置) ) 第四种常见画法:plt.subplot() 画出多个 figure ...
「方式二:通过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个图:散点图 ...
方式二:通过figure的add_subplot import numpy as np import pandas as pd import matplotlib.pyplotas plt # author: chenqionghe fig=plt.figure() # 画第1个图:折线图 x=np.arange(1,100) ax1=fig.add_subplot(221) ax1.plot(x,x*x)