1、plt画图保存图片不完整
有时候使用savefig保存图片的时候,会发现保存的图片是不完整的,这时,只需要在保存图片的命令中加入bbox_inches='tight'
即可,如:
plt.savefig('text.png',dpi=500,bbox_inches='tight')
2、plt不显示中文
plt.rcParams['font.family']=["SimHei"]# 显示汉字 SimHei黑体,STsong 华文宋体还有font.style font.size等
3、plt 修改style
plt.style.use('seaborn-white')
查看style 类型
print(len(plt.style.available))
print(plt.style.available)
28
[‘Solarize_Light2’, ‘_classic_test_patch’, ‘_mpl-gallery’, ‘_mpl-gallery-nogrid’, ‘bmh’, ‘classic’, ‘dark_background’, ‘fast’, ‘fivethirtyeight’, ‘ggplot’, ‘grayscale’, ‘seaborn’, ‘seaborn-bright’, ‘seaborn-colorblind’, ‘seaborn-dark’, ‘seaborn-dark-palette’, ‘seaborn-darkgrid’, ‘seaborn-deep’, ‘seaborn-muted’, ‘seaborn-notebook’, ‘seaborn-paper’, ‘seaborn-pastel’, ‘seaborn-poster’, ‘seaborn-talk’, ‘seaborn-ticks’, ‘seaborn-white’, ‘seaborn-whitegrid’, ‘tableau-colorblind10’]
4、plt.style.use(‘seaborn’)不能显示中文问题
把plt.style.use('seaborn')
放在修改中文代码
的前面,不然会被覆盖了!
plt.style.use('seaborn-white')
plt.rcParams['font.sans-serif'] =["SimHei"]#解决中文乱码问题
5、保存图片边缘留白太多
第一种方式:保存图片之前加一句代码
plt.subplots_adjust(left=0.1, right=0.9, top=0.9, bottom=0.1)
# plt.subplots_adjust(left=0, right=1, top=1, bottom=0) # 完全不留空白
plt.savefig('照片.png')
第二种方式‘:添加bbox_inches='tight'
plt.savefig('照片.png',bbox_inches='tight')
# 会更改之前设置图片的像素大小
6、绘图不从原点开始
plt.xlim(0,len(x)-1)