mac matplotlib显示中文

以下默认字体,在mac ventura上测试能成功显示中文:

python 复制代码
import matplotlib.pyplot as plt
import matplotlib

#from matplotlib import font_manager
#plt.rcParams['font.sans-serif'] = ['Heiti TC']
 
#plt.rcParams['font.sans-serif'] = ['Songti SC']
 
#plt.rcParams['font.sans-serif'] = ['Arial Unicode MS']
 
plt.rcParams['font.sans-serif'] = ['PingFang HK']



# 创建数据
x = [1, 2, 3, 4, 5]
y1 = [2, 1, 9, 8, 10]
y2 = [100, 300, 500, 700, 900]

# 创建图形和轴
fig, ax1 = plt.subplots()

# 绘制左侧Y轴数据
ax1.plot(x, y1, 'b-')
ax1.set_xlabel('X轴')
ax1.set_ylabel('左侧Y轴', color='b')

# 创建第二个Y轴
ax2 = ax1.twinx()

# 绘制右侧Y轴数据
ax2.plot(x, y2, 'r--')
ax2.set_ylabel('右侧Y轴', color='r')

# 显示图形
plt.show()

显示效果:

相关推荐
laocooon52385788640 分钟前
对传入的 x , y 两个数组做折线图, x 对应 x 轴, y 对应 y 轴。并保存到 Task1/image1/T2.png
python·numpy·pandas·matplotlib
DisonTangor1 小时前
Mac Studio配备1.5 TB显存——基于雷电5的远程直接内存访问技术
人工智能·macos·开源·aigc
天庭鸡腿哥2 小时前
输入序列号,可激活正版软件!
microsoft·macos·visual studio·everything
FreeBuf_14 小时前
朝鲜黑客组织“传染性面试“瞄准macOS:新型“DriverFixer“窃密工具浮出水面
macos·面试·职场和发展
Zfox_20 小时前
无缝穿越系统边界:节点小宝4.0如何让我的Mac/iOS像访问本地盘一样操控Windows
windows·macos·ios·节点小宝
MicJordan1 天前
macos安装Claude提示command not found
macos
坠金1 天前
mac电脑网络卡顿解决方法
macos
写点啥呢1 天前
MacOS远程桌面报错0x207解决方法
macos
渡我白衣1 天前
Python 与数据科学工具链入门:NumPy、Pandas、Matplotlib 快速上手
人工智能·python·机器学习·自然语言处理·numpy·pandas·matplotlib
CrankZ1 天前
幕译 1.7--本地字幕生成与翻译--支持macOS,Windows
macos·whisper