mac下用python画图中文不会乱码的代码
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['Arial Unicode MS'] # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号
barWidth = 0.2
# 设置柱子的高度
bars1 =[61,59,64,64]
bars2 = [68,135,185,233]
bars3= [79,151,229,309]
r1=[0,1,2,3]
r2 = [x + barWidth for x in r1]
print(r2)
r3 = [x + barWidth for x in r2]
print(r3)
r4 = [x + barWidth for x in r3]
print(r4)
# 创建柱子
plt.bar(r1, bars1, color='#3CB371', width=barWidth, edgecolor='white', label='哈哈哈哈哈哈哈',hatch="////")
plt.bar(r2, bars2, color='#00BBFF', width=barWidth, edgecolor='white', label='MinMax',hatch="\\\\\\")
plt.bar(r3, bars3, color='#FF5511', width=barWidth, edgecolor='white', label='MIN-Max-Min',hatch="---")
# 添加x轴名称
plt.xticks([r + barWidth for r in range(len(bars1))], [2000,4000,6000,8000])
plt.xlabel(" Numbers of Cloud Task")
plt.ylabel("Maskespan/s")
# 创建图例ll
plt.legend()
# 展示图片
# plt.savefig('test1.png')
plt.show()
效果图片