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

显示效果:

相关推荐
高兴就好(石1 天前
Mac使用llama.cpp
macos·llama
星辰即远方1 天前
UITableView操作拓展
macos·ios·xcode
刘某某.1 天前
macOS 终端美化完整教程(Ghostty + Zsh + Starship Catppuccin Powerline)
macos
咦呀1 天前
macOS 上 SVN 报错 "SQLite 编译为 X.XX,运行时为 X.XX" 的完整解决方案
macos
秋雨梧桐叶落莳1 天前
iOS——Masonry约束内容整理
开发语言·学习·macos·ios·objective-c·cocoa
pop_xiaoli1 天前
【iOS】类和分类的加载
macos·ios·objective-c·cocoa
国科安芯1 天前
空间辐射环境下抗辐射 MCU 可靠性机理及航空安全应用研究综述
单片机·嵌入式硬件·macos·无人机·cocos2d·risc-v
一个人旅程~1 天前
ARM版的windows(macbook虚拟机使用)在国内外技术平台有哪些版本可以选择?
windows·经验分享·macos·电脑
qq_327395031 天前
MacOS安装openEMS
macos·openems
qq_283720052 天前
Python3 模块精讲:Matplotlib—— 数据可视化、绘图从零基础到实战精通
信息可视化·matplotlib