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

显示效果:

相关推荐
weixin_462446232 小时前
在 Linux / macOS 下使用 Docker 快速部署 PaddlePaddle + 运行 PaddleOCR 表格 PDF 解析示例
linux·macos·docker·paddleocr
新缸中之脑2 小时前
Clawdbot安装:VPS vs.Mac Mini
macos
如果曾经拥有13 小时前
matplotlib - 绘制ROC曲线95%置信区间
matplotlib
muddjsv21 小时前
了解Matplotlib 核心基础:环境配置 + 三层架构 + 绘图流程
matplotlib
2501_916007471 天前
不越狱如何查看iOS 应用的详细信息及其文件目录结构
android·macos·ios·小程序·uni-app·cocoa·iphone
芒鸽1 天前
macos上Rust 命令行工具鸿蒙化适配完全攻略
macos·rust·harmonyos
山有木兮啊1 天前
VSCode Remote-SSH 连接Mac卡在初始化VSCode
vscode·macos·ssh
一个写bug的程序员1 天前
Mac自启服务关闭方式
macos
梁下轻语的秋缘1 天前
初学者避坑指南:Mac 虚拟机搭建 Keil5 STM32 环境 + 解决 ST-Link USB Command Error 报错
windows·stm32·macos
天荒地老笑话么1 天前
macOS 终端:本机隐藏用户名,但 SSH 登录时仍显示(Oh My Zsh + agnoster,更安全)
windows·macos·网络安全