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 小时前
【iOS】 单例模式
macos·objective-c·cocoa
FreeBuf_11 小时前
苹果用户速更新!macOS存严重漏洞,用户隐私数据面临泄露风险
macos
Thomas214311 小时前
macos deepctr_torch虚拟环境配置
macos
wxl78122711 小时前
MacOS 运行CosyVoice
macos·cosyvoice·语音自然
lichong95112 小时前
【混合开发】vue+Android、iPhone、鸿蒙、win、macOS、Linux之video 的各种状态和生命周期调用说明
android·vue.js·macos
程序务虚论12 小时前
mac M1上安装windows虚拟机报错
windows·macos·parallels
今天头发还在吗14 小时前
【Go】:mac 环境下GoFrame安装开发工具 gf-cli——gf_darwin_arm64
macos·golang·go·gf-cli
小妖66617 小时前
MAC在home下新建文件夹报错“mkdir: test: Operation not supported”
macos
北冥有鱼被烹1 天前
【问题解决】mac笔记本遇到鼠标无法点击键盘可响应处理办法?(Command+Option+P+R)
macos
Winter_Sun灬1 天前
Mac开发第一步 - 安装Xcode
ide·macos·xcode