科研论文配图绘制指南——基于Python—第二章1.matplotlib

第二章

2.0 安装所需的环境

attrs==23.1.0
certifi==2023.7.22
click==8.1.6
click-plugins==1.1.1
cligj==0.7.2
colorama==0.4.6
cycler==0.11.0
Fiona==1.9.4.post1
geopandas==0.13.2
importlib-metadata==6.8.0
kiwisolver==1.4.4
matplotlib==3.4.3
numpy==1.24.4
packaging==23.1
pandas==2.0.3
Pillow==10.0.0
proplot==0.9.7
pyparsing==3.1.1
pyproj==3.5.0
python-dateutil==2.8.2
pytz==2023.3
scipy==1.10.1
seaborn==0.12.2
shapely==2.0.1
six==1.16.0
tzdata==2023.3
zipp==3.16.2

使用的python版本为3.8,上述依赖可以放在requirement.txt中,使用下面命令:

pip install -r requirements.txt

即可完成环境的配置。

2.1 Matplotlib

2.1.1 图形元素

  • 基础类:点、线、文本、网格、标题、图例
  • 容器类:图形、坐标图形、轴、刻度

在这里插入图片描述

2.1.2 图层顺序

不同的艺术对象在坐标图形中默认的图层顺序如下:

艺术对象order
Images(AxesImage, FigureImage, BboxImage)0
Patch / PatchCollection1
Line2D / LineCollection2
Text3
Inset axes & Legend4

在这里插入图片描述

2.1.5 子图绘制

plt.subplot()

在这里插入图片描述

add_subplot() #使用起来不太方便

在这里插入图片描述

subplots()#可以选择共享x轴和y轴

在这里插入图片描述

axes() #可以为figure添加画布

在这里插入图片描述

subplot2grid()#绘制不规则的子图

在这里插入图片描述

gridspec.GridSpec() #可以指定子图网格的几何形状,能与上面的函数实现同样的功能

在这里插入图片描述

subplot_mosaic()#进行视觉布局

2.1.7 结果保存

  • 在绘图中,可以使用plt.show(),直接展示绘图结果;也可以直接将绘图结果保存为jpg、png等格式
fig.savefig('result.png')
plt.show()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值