mac matplotlib显示中文

以下默认字体,在mac ventura上测试能成功显示中文:


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
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值