fig, ax = plt.subplots() im = ax.pcolormesh(data, cmap=cmap, norm=norm) # 创建一个新的子轴对象,并设置其位置和大小 cax = fig.add_axes([0.85, 0.1, 0.07, 0.6]) # x, y, width, height # 添加颜色条到子轴对象中 cbar = plt.colorbar(mappable=im, cax=cax) # 更新图像显示 plt.s...
import matplotlib.pyplot as plt fig = plt.figure(figsize=(10, 5), dpi=80, facecolor='yellow', edgecolor='blue', linewidth=2.0, ) ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], projection='rectilinear', polar=False) plt.show() demo 运行结果 参考链接 :matplotlib.figure - Matplotlib 3.5.1...
plt.figure创建一张画布,使用plt.subplot函数或其他的作图函数在这张画布上作一幅图。如果要作多幅并列的图,使用plt.add_subplot函数。 plt.rcParams['font.family'] = 'Microsoft YaHei' fig1 = plt.figure(figsize=[8,7]) # ax1 = fig1.add_subplot(121) #1行2列,第1幅图 ax1.plot(x, y1) #pl...
fig=plt.figure() # 通过fig.add_axes给设定的axes调整位置和大小 # 主要的axes axes1 = fig.add_axes([0.1, 0.1, 0.8, 0.8]) # main axes # 插入的axes axes2 = fig.add_axes([0.55, 0.55, 0.3, 0.3]) # inset axes y = np.sin(x) # 分别在axes1区域和axes2区域作图 axes1.plot(x, y...
float)path=Path(vertices,codes)pathpatch=PathPatch(path,facecolor='None',edgecolor='green')fig=plt.figure(figsize=(4,4),dpi=500)ax=fig.add_axes([0,0,1,1],projection=ccrs.PlateCarree())ax.add_feature(cfeat.OCEAN)ax.add_feature(cfeat.LAND)ax.set_extent([0,100,0,50])ax.add_patch...
y轴的刻度:plt.yticks(item) (2)源代码 # 导入模块importmatplotlib.pyplotaspltimportnumpyasnp# 数据x = np.linspace(-10,10,100) y = x**2# 绘图plt.plot(x, y)# 设置轴的刻度plt.xticks(range(-8,8,2)) plt.yticks([0, -3, -6,7,15,20,37,48,72])# 展示plt.show() ...
fig=plt.figure(constrained_layout=False, facecolor='0.9') gs=fig.add_gridspec(nrows=3, ncols=3,left=0.05,right=0.75, hspace=0.1, wspace=0.05) ax0=fig.add_subplot(gs[:-1, :]) annotate_axes(ax0,'ax0') ax1=fig.add_subplot(gs[-1, :-1]) ...
add_subplot与add_axes都是面对象figure编程的,pyplotapi中没有此命令 (1)add_subplot新增子图 add_subplot的参数与subplots的相似 import numpy as np import matplotlib.pyplot as plt x = np.arange(0, 100) #新建figure对象 fig=plt.figure() #新建子图1 ax1=fig.add_subplot(2,2,1) ax1.plot(x, ...
plt.axes创建子图 创建坐标轴最基本的方法就是使用plt.axes 函数。这个函数的默认配置是创建一个标准的坐标轴,填满整张图。它还有一个可选参数,由图形坐标系统的四个值构成。这四个值分别表示图形坐标系统的[bottom,left,width,height](底坐标、左坐 标、宽度、高度),数值的取值范围是左下角(原点)为 0,右上...
mpl.ticker import LongitudeFormatter,LatitudeFormatter plt.rcParams['font.sans-serif']=['SimHei'] fig=plt.figure(figsize=(2,2),dpi=400) ax=fig.add_axes([0,0,1,1],projection=ccrs.PlateCarree(central_longitude=110)) ax.add_feature(cf.LAND.with_scale('110m')) ax.add_feature(cf.OCEAN...