matplotlib中的savefig期间引发Python类型错误



我有一个python脚本,它使用pandas数据帧和matplotlib来创建一些绘图。以前,该脚本运行良好,没有"折旧"或"未来警告"。我没有使用最新的python、numpy、matplotlib等,但大约在1岁以内,例如:pandas~0.9、python 3.7.5。我被迫重新安装windows,所以只安装了一个pip来获得我需要的软件包,所以它们现在都是最新的。然而,对于最新的软件包,当以下代码运行时,我现在得到了一个exeption。

出现异常:TypeError必须是实数,而不是str";

当调用保存图形的代码时抛出:

fig.savefig(rf'{cfg.output_dir}plots/data_gaps.png', dpi=100, format='png', transparent=True)

然而,当它需要int或float时,我看不到任何被赋予字符串的行。我甚至尝试将代码简化为:fig.savefig('data_gaps.png')仍然抛出错误,所以我假设它来自于构造图的时候。

fig, ax = plt.subplots(nrows=int(len(gap_list)), ncols=1, figsize=(12,int(fig_size(gap_list))), sharex=True)
fig.suptitle('Recording Gaps')
for ch in gap_list:
i = gap_list.index(ch)
resample_s = 4*ch_gap[ch]['rec_rate']
ylabel = ch + ' (' + ch_gap[ch]['board'] +') - '+ ch_gap[ch]['unit']
data = df[ch].resample(f'{resample_s}s').mean()
is_nan = data.isnull()
# if `ax` is a numpy array then index it, else just use `ax`
ax_i = ax[i] if isinstance(ax, np.ndarray) else ax
ax_i.fill_between(data.index, 0, (is_nan*data.max()), color='r', step='mid', linewidth='0', alpha=0.5)
ax_i.plot(data.index, data, color='b', linestyle='-', marker=',', label=ylabel)
ax_i.legend(loc='upper left')

figsize((是一个函数,它根据gap_list列表的大小返回适当的图形高度。我试着将其转换为int,只对一个数字进行硬编码,它仍然会抛出错误。有人看到我哪里出错了吗?

像往常一样,Python告诉我们它为什么不起作用:

线宽="0",将宽度从字符串更改为int,线宽=0

我想以前版本的matplotlib会自动为我修复这个问题,而不会引发警告或异常。

最新更新