<<--B站..........欢迎来到DGX的博客..........GitHub-->>

我的B站

如何解决matplotlib模块中的中文乱码

如何解决matplotlib模块中的中文乱码

核心代码 

## 设置属性防止中文乱码
mpl.rcParams['font.sans-serif'] = [u'SimHei']
mpl.rcParams['axes.unicode_minus'] = False

  

例子:

1.没有上面代码的

 

import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np

## 设置属性防止中文乱码
# mpl.rcParams['font.sans-serif'] = [u'SimHei']
# mpl.rcParams['axes.unicode_minus'] = False

fig,ax = plt.subplots()
x = np.linspace(0,20,1000)
ax.plot(x,np.cos(x))
ax.axis('equal')
ax.annotate('最大值',xy = (6.28,1),xytext = (10,4),arrowprops = dict(facecolor = 'black',shrink = 0.05))
ax.annotate('最小值',xy = (5*np.pi,-1),xytext=(2,-6),arrowprops = dict(arrowstyle = "->",connectionstyle ="angle3,angleA = 0,angleB=-90" ))
plt.show()

  

 

 

2.添加上面代码

import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np

## 设置属性防止中文乱码
mpl.rcParams['font.sans-serif'] = [u'SimHei']
mpl.rcParams['axes.unicode_minus'] = False

fig,ax = plt.subplots()
x = np.linspace(0,20,1000)
ax.plot(x,np.cos(x))
ax.axis('equal')
ax.annotate('最大值',xy = (6.28,1),xytext = (10,4),arrowprops = dict(facecolor = 'black',shrink = 0.05))
ax.annotate('最小值',xy = (5*np.pi,-1),xytext=(2,-6),arrowprops = dict(arrowstyle = "->",connectionstyle ="angle3,angleA = 0,angleB=-90" ))
plt.show()

  

 

posted @ 2020-11-12 16:47  DG息  阅读(426)  评论(0)    收藏  举报