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

显示效果:

相关推荐
郝学胜-神的一滴4 小时前
Effective Python 条款35:用类封装替代生成器异常注入
开发语言·人工智能·python·金融·pandas·scikit-learn·matplotlib
oil欧哟14 小时前
Oil Studio 的产品思路与日常使用方式:在 Mac 上录口播演示,并接入 AI Agent 精剪与自动录屏
人工智能·macos
小毛球.2 天前
第 3 篇:IDEA 最新版下载与完整安装教程(Mac)
java·macos·intellij-idea·idea
CodeClimb3 天前
Mac 磁盘无法推出(DMG外接盘)排查处理教程
macos
Karl_fang4 天前
🥳 再也不用拿起手机抄验证码!我做了一个 Android → Mac 的「验证码接力」工具
前端·macos·ai编程
csdn_aspnet5 天前
macOS 10 、Docker 玩轉 MySQL
运维·mysql·macos·docker·容器·mac
秋雨梧桐叶落莳6 天前
【iOS】Block底层详解
macos·ios·cocoa
高调的涵涵7 天前
café 和 café 不是一个文件名
macos
独隅10 天前
WebStorm macOS 安装部署与高效调优完全指南
ide·macos·webstorm
独隅10 天前
WebStorm macOS 安装调优与实战效能全景
ide·macos·webstorm