好的,这是我第一次在这里提问,请耐心等待;-)
我正在尝试使用 matplotlib 创建一个带有两个 y 轴的子图系列,并保存该图。我正在使用 GridSpec 来为子图创建网格,并意识到它们有点重叠,这不是我想要的。因此,我尝试使用 tight_layout() 来解决这个问题,根据 matplotlib 文档的说法应该可以完美解决。简化一下,我的代码大致如下:
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
fig = plt.figure(num=None, facecolor='w', edgecolor='k')
grid = gridspec.GridSpec(2, numRows)
# numRows comes from the number of subplots required
# then I loop over all the data files I'm importing and create a subplot with two y-axes each time
ax1 = fig.add_subplot(grid[column, row])
# now I do all sorts of stuff with ax1...
ax2 = ax1.twinx()
# again doing some stuff here
当数据处理循环完成并且我创建了所有子图后,最终结果如下:
fig.tight_layout()
fig.savefig(str(location))
就我所知,这应该可以工作,但是当调用tight_layout()时,我从函数self.subplotpars得到一个ValueError: left不能>= right。我的问题是:如何找出导致此错误的原因并如何修复它?