matplot问题汇总

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)
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值