import matplotlib.pyplot as plt # 生成一些测试数据 data = [[1, 2], [3, 4]] cmap = 'viridis' norm = plt.Normalize(vmin=0, vmax=5) fig, ax = plt.subplots() im = ax.pcolormesh(data, cmap=cmap, norm=norm) # 创建一个新的子轴对象,并设置其位置和大小 cax = fig.add_axes([0.85...
首先,我们需要导入matplotlib库,代码如下: importmatplotlib.pyplotasplt 1. 步骤二:创建图形对象和坐标轴对象 接下来,我们需要创建图形对象和坐标轴对象,代码如下: fig,ax=plt.subplots() 1. 步骤三:绘制图形 然后,我们可以根据具体需求绘制相应的图形,这里以绘制一个简单的折线图为例: x=[1,2,3,4,5]y=[2...
plt.xlabel('x',fontsize=14)# fontsize:设置字体大小 plt.ylabel('x^3',fontsize=14)plt.rcParams['font.sans-serif']=['SimHei']# 用来正常显示中文标签,字体可自由设置电脑中自带的字体 # 给图标添加标题 plt.title('折线绘制图',fontsize=24)# 显示绘制的图 plt.show() 运行效果如下: Matplotlib ...
基于matplotlib库,通过plt.subplots(nrows=6, ncols=5)定义子图,返回一个包含figure和axes对象的元组,详解见代码(使用数组循环比较简洁)。 ''' Created on 2020年8月16日 @author: xiaoyw ''' import numpy as np import pandas as pd import matplotlib.pyplot as plt from matplotlib.pyplot import MultipleLo...
plt.gcf().gca().add_artist(circle1) 带箭头坐标 import matplotlib.pyplot as plt import mpl_toolkits.axisartist as axisartist fig = plt.figure() ax = axisartist.Subplot(fig, 111)#创建一个绘图区对象ax fig.add_axes(ax) #将绘图区对象添加到画布中 ax.axis["bottom"].set_axisline_style("-|...
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]) ...
sqrt(X**2+Y**2) return X,Y,Z x,y,z=data() fig=plt.figure(figsize=(2.6,2),dpi=500) ax=fig.add_axes([0,0,1,1]) cf=ax.contourf(x,y,z*100,norm=LogNorm())###在这里有不同 fc=fig.colorbar(cf) ax2=fc.ax ax2.set_title('指数色条',fontsize=5) ax2.tick_params(...
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...
(1)add_subplot新增子图 add_subplot的参数与subplots的相似 例子 importnumpy as npimportmatplotlib.pyplot as plt x= np.arange(0, 100)#新建figure对象fig=plt.figure()#新建子图1ax1=fig.add_subplot(2,2,1) ax1.plot(x, x)#新建子图3ax3=fig.add_subplot(2,2,3) ...
import matplotlib.pyplot as pltimport numpy as npx = np.linspace(0.05,20,2000)y = np.sin(x)plt.plot(x,y,ls='--',c='k',lw=2,label='plot figure')plt.legend()plt.axhline(0.5,ls='-.',c='r',lw=1)plt.axvline(7.5,ls='-.',c='r',lw=1)plt.savefig('./addline.png...