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 天前
IOS上收费的软件,Android上免费!
macos·visual studio·everything
天庭鸡腿哥1 天前
大小不足1M,干翻Windows!
microsoft·macos·visual studio·everything
怎么没有名字注册了啊1 天前
(Mac)Visual Studio Code 配置 C/C++运行环境
c++·vscode·macos
耘田2 天前
一块移动硬盘支持Mac备份和通用文件存储
macos
杂货铺的小掌柜2 天前
MAC版IDEA常用快捷键
java·macos·intellij-idea
渡我白衣3 天前
计算机组成原理(11):加法器
python·机器学习·numpy·pandas·matplotlib·计组·数电
老歌老听老掉牙3 天前
使用 Matplotlib 自定义坐标轴字体及刻度样式详解
python·matplotlib
江下枫3 天前
macOS 内置反恶意软件三板斧
macos
昵称已被吞噬~‘(*@﹏@*)’~3 天前
【强化学习】MacOS (M1芯片)上最新版本 MuJoCo 通用安装教程(最简洁),PS:不是 mujoco_py 的老版本
python·macos·机器学习·强化学习·mujoco
小锋学长生活大爆炸4 天前
【教程】MacOS绕过Apple Develop ID获取麦克风权限
macos·swift