Image size of 512922x322 pixels is too large. It must be less than 2^16 in each direction

plt.figure(figsize=(10,8))

sns.regplot(x=data[num],y=data['y'], marker="o",ci=95,
                scatter_kws={"color":"b","alpha":0.2,"s":3},
                fit_reg=False
                )#线性回归   ci=95表示95%置信区间
x = data['x'].to_numpy()
y = data['y'].to_numpy()
    
parameter = np.polyfit(x, y, 1) # n=1为一次函数,返回函数参数
print(parameter)
f = np.poly1d(parameter) # 拼接方程


ax=plt.gca();#获得坐标轴的句柄
ax.text(0,1,'$y=$'+str(round(parameter[0],4))+'$x$'+'+'+str(round(parameter[1],2)),fontsize=15,transform=ax.transAxes)

plt.plot(x, f(x),"--",color='r')
plt.rc('ytick',labelsize=15)
plt.rc('xtick',labelsize=15)
     
plt.savefig(path+ str(num) + '.png', bbox_inches = 'tight')
plt.savefig(path+ str(num) + '.eps', bbox_inches = 'tight')

plt.show()

原因:图像尺寸超出了范围,问题来自plt.text()

解决方法:

plt.text()中添加transform=ax.transAxes

使用 transform=ax.transAxes 整个代码表示坐标是相对于轴边界框给出的,

(0,0)是轴的左下角,(1,1)是右上角。

reference:

https://www.osgeo.cn/matplotlib/tutorials/text/text_props.html

https://blog.csdn.net/xu380393916/article/details/105009617

https://stackoverflow.com/questions/52375207/matplotlib-error-image-size-of-362976x273-pixels-is-too-large

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值