我有一个库函数,可将数据绘制到包含多个子图的pyplot图中。我只是向所有子图添加了网格线,但它们覆盖了实际数据,但我希望它们位于背景中。我尝试更改执行plotting和ax.plot()ax.grid()命令的顺序,但这没有影响。有没有办法迫使网格进入背景?
相关的奖励问题:我也使用axhline来指定x = 0线,但是即使在另一条线中指定了它,它也始终采用网格颜色...
def plot_the_things(fig=None):
# in case no figure is provided, make a new one,
# otherwise add to the existing one
plot_fig=fig if fig else plt.figure()
#[...some calculations of data ...]
plot_ax1 = plot_fig.add_subplot(3,3,1)
plot_ax1.axhline(y=0, ls='-', color='0.5')
plot_ax1.plot(self.diff_3[:,0],self.diff_3[:,1])
# [...setting labels, adapt axes limits in case the new data needs wider ones..]
plot_ax1.grid(b=True, which='major', axis='both', c='0.75', ls='-', linewidth=1)
# this is repeated in similar fashion for the other axes -- there are 9 of
# them, each plotting something different in a different axes
多次调用此功能。更准确地说:它实际上是课程的一部分。我有该类的多个实例,并调用所有同一个实例对象。然后,每个实例都会绘制自己的数据,效果很好,甚至axhline()
正确显示了数据(在数据下方!),但是在我输入添加网格的命令后,它始终显示在数据顶部并覆盖了axhline,这很烦人。
... 有任何解决这个问题的方法吗?
(我认为我可以并且也许也应该将所有只需要运行一次的东西移动到一个不会被重复执行但时间和精力都很少的地方,所以我采用了最快的方法。 ,但我不希望这会改变任何东西)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句