python模块Matplotlib.pyplot中内置样式’seaborn’和导入中文有冲突
代码
import matplotlib.pyplot as plt
plt.rcParams['font.family']='SimHei' #指定默认字体 SimHei为黑体
plt.rcParams['axes.unicode_minus']=False
plt.style.use('seaborn')
fig,ax = plt.subplots()
ax.scatter(2,4,s=200)
#设置图标标题并给坐标加上标签。
ax.set_title('平方数',fontsize=24)
ax.set_xlabel('值',fontsize=14)
ax.set_ylabel('值的平反',fontsize=14)
#设置刻度标记的大小。
ax.tick_params(axis='both',which='major',labelsize=14)
plt.show()
运行如下
下面不运行’seaborn’的代码
import matplotlib.pyplot as plt
plt.rcParams['font.family']='SimHei' #指定默认字体 SimHei为黑体
plt.rcParams['axes.unicode_minus']=False
#plt.style.use('seaborn')
fig,ax = plt.subplots()
ax.scatter(2,4,s=200)
#设置图标标题并给坐标加上标签。
ax.set_title('平方数',fontsize=24)
ax.set_xlabel('值',fontsize=14)
ax.set_ylabel('值的平反',fontsize=14)
#设置刻度标记的大小。
ax.tick_params(axis='both',which='major',labelsize=14)
plt.show()在这里插入代码片
运行如下
具体什么原因没搞懂,麻烦有懂的大佬帮帮忙,谢谢。