matplotlib.pyplot.figure() 返回一个图形对象,这个对象可以用来使用 add_subplot() 方法向图中添加子图。import matplotlib.pyplot as plt x=[1,2,3,4,5,6] y=[4,3,5,6,7,4] fig=plt.figure() subplot1=fig.add_subplot(2,1,1) subplot1.plot(x,
调用figure创建一个绘图对象,并且使它成为当前的绘图对象 plt.figure(figsize=(8,4)) 1. 通过figure参数可以指定绘图对象的宽度和高度,单位是英寸。 2、创建子图: 方法一、调用figure的方法add_subplot可以创建并选定子图: p1=plt.figure(figsize=(8,4)) ax3=p1.add_sibplot(2,2,3) 1. 2. 方法二、调用...
# 创建图形和子图 fig = plt.figure(figsize=(12, 6)) ax1 = fig.add_subplot(1, 2, 1, projection='3d') # 3D曲面图 ax2 = fig.add_subplot(1, 2, 2) # 等高线投影图 # 绘制3D曲面图 surf = ax1.plot_surface(x, y, z, cmap='viridis', edgecolor='none') ax1.set_xlabel('X axis...
x= np.linspace(0,10,1000) plt.figure()#创建一个画布 plt.subplot(2,1,1)#创建两个子图,定位到第一列第一行(注意这里是先列后行 plt.plot(x,np.sin(x))#画图 plt.subplot(2,1,2)#定位到第一列第二行 plt.plot(x,np.cos(x))#画图 plt.show()#展示图片 #要返回来修改第一张图时还要重新...
from matplotlib import pyplot as plt from matplotlib.ticker import MultipleLocator import numpy as np # Two example plots fig = plt.figure() ax1 = fig.add_subplot(2,2,1) ax2 = fig.add_subplot(2,2,2) spacing = 0.5 # This can be your user specified spacing. minorLocator = MultipleLocat...
fig = plt.figure()# 添加第一个子图 ax1 = fig.add_subplot(2, 2, 1) # 2行2列的布局中的第1个位置 ax1.plot(x, y1)ax1.set_title('First subplot')# 添加第二个子图 ax2 = fig.add_subplot(2, 2, 2)ax2.plot(x, y2)ax2.set_title('Second subplot')# 添加第三个子图 ax3 = ...
import numpy as np import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) x=[1,2,3,4,5,6,7,8,9,10] y=[1,1,1,2,10,2,1,1,1,1] line, = ax.plot(x, y) ymax = max(y) xpos = y.index(ymax) xmax = x[xpos] ax.annotate('local max', xy...
#建立画布 fig=plt.figure(figsize=(25,18)) #坐标轴1 ax1=fig.add_subplot(111) ax1.plot(pe_df["date"],pe_y-new_risk_free_rate,linewidth=2) #坐标轴1标签 ax1.set_ylabel("(100 / PE) - (risk free rate)",fontsize=23) #图例位置 ...
你可以通过 fig.add_subplot() 方法来添加 Axes 对象,并指定其在 Figure 中的位置和大小。例如: python # 创建一个图形对象 fig = plt.figure() # 添加一个 2x2 的子图网格,并选择第一个子图进行绘图 ax1 = fig.add_subplot(2, 2, 1) ax1.plot(x, y) ...
import matplotlib.gridspec as gridspec#调用网格 fig=plt.figure(num=1,figsize=(4,6))#创建画布 gs=gridspec.GridSpec(3,3)#设定网格 ax1=fig.add_subplot(gs[0,:])#选定网格 ax1.plot([1,2,3,4],[1,2,3,4]) ax2=fig.add_subplot(gs[1,:-1]) ax2.plot([1,2,3,4],[1,2,3,4])...