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()

显示效果:

相关推荐
扑火的小飞蛾5 小时前
【macOS】n8n 安装配置笔记
笔记·macos
TO_ZRG6 小时前
iOS 符号表文件概要
macos·ios·cocoa
默默在路上6 小时前
M芯片使用VMware Fusion安装CentOS Stream 9教程
linux·macos·centos
TheNextByte17 小时前
如何在Mac上收发Android信息 [2026 指南]
android·macos
耘田7 小时前
 macOS Launch Agent 定时任务实践指南
java·开发语言·macos
不爱吃糖的程序媛7 小时前
macOS 系统本地安装 openJiuwen 完整指南
macos
William.csj7 小时前
Mac——一款支持跨平台的与服务器之间的远程传输工具 FileZilla
macos·filezilla
Nightmare0041 天前
Mac打开终端
macos
亚里随笔1 天前
vscode mac常用技巧—快捷键
ide·vscode·macos
Nightmare0041 天前
Mac 安装brew
大数据·macos