matplot

使用 matplpot 画图

首先是字体问题。matplot 能够使用的字体参见 ~/.cache/matplotlib/fontlist-v330.json 中的内容。有些字体 matplot 是检测不到的。例如 Noto Sans CJK SC 没有,只有 Noto Sans CJK JP。

如果存在图中存在中文,需要先设置字体:

import matplotlib.pyplot as plt
import pandas

plt.rcParams['font.sans-serif'] = ['Noto Sans CJK JP']  # 显示中文标签
plt.rcParams['axes.unicode_minus'] = False

然后是画图:

#!/bin/python3
import matplotlib.pyplot as plt
import pandas

plt.rcParams['font.sans-serif'] = ['Noto Sans CJK JP']  # 显示中文标签
plt.rcParams['axes.unicode_minus'] = False

data = pandas.read_csv('1.csv')

# 均一温度
plt.hist(x=data.均一温度, bins=5, color='grey', edgecolor='black', label='气液两相包裹体')
plt.xlabel('均一温度/°C')
plt.ylabel('频数')

plt.legend()

plt.savefig('温度分布直方图')

plt.clf()

# 盐度
plt.hist(x=data.盐度, bins=5, color='grey', edgecolor='black', label='气液两相包裹体')
plt.xlabel('盐度/%')
plt.ylabel('频数')

plt.legend()

plt.savefig('盐度分布直方图')
plt.clf()

# 散点图
plt.scatter(x=data.盐度, y=data.均一温度, color='grey', label='成矿阶段')

plt.xlabel('盐度/%')
plt.ylabel('均一温度/°C')

plt.legend()

plt.savefig('温度-盐度散点图')
plt.clf()
Last moify: 2023-02-04 01:03:05
Build time:2025-07-18 09:41:42
Powered By asphinx