Matplotlib.pyplot 常用操作

单个图表的基本操作


导入模块

import matplotlib.pyplot as plt

设置图像大小

plt.figure(figsize=(10, 6))

绘制折线图

plt.plot(time, AODs_550nm)

设置标题

plt.title("AOD_550nm")

设置坐标轴

# 坐标轴名称
plt.ylabel("AOD_550nm")

# 坐标轴范围
plt.ylim((0,1)) 

# 坐标轴刻度:每十个标注一个,并垂直标注刻度
plt.xticks([i for i in range(0,len(time),10)],[time[i] for i in range(0, len(time), 10)], rotation='vertical')

设置边框

# 获取边框
ax = plt.gca()

# 设置右、上边框不可见
# ax.spines["right"].set_visible(False)
# ax.spines["top"].set_visible(False)

绘制格网

plt.grid(axis="y", color='black', linestyle='--', linewidth=1)

设置图例

# plot时加上label属性
# plt.plot(time, AODs_550nm, label ="AOD 550nm")
plt.legend()

正常显示中文

plt.rcParams['font.sans-serif'] = ['SimHei']

正常显示负号

plt.rcParams['axes.unicode_minus'] = False

保存图像

# 要在plt.show()之前保存
plt.savefig("./aod550nm.jpg")


多个图表的基本操作


产生子图

# 将图像分为1行2列,当前选中第一个位置
plt.subplot(1,2,1)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容