在pyplot中绘制网格线和数据的顺序

扎克

我有一个库函数,可将数据绘制到包含多个子图的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,这很烦人。

... 有任何解决这个问题的方法吗?

(我认为我可以并且也许也应该将所有只需要运行一次的东西移动到一个不会被重复执行但时间和精力都很少的地方,所以我采用了最快的方法。 ,但我不希望这会改变任何东西)

法伦索斯

zorder对您的plotaxhline呼叫使用kwarg grid绘制在zorder=2.5,因此将axhline放在其plot上方:

plot_ax1.axhline(y=0, ls='-', color='0.5', zorder=3)
plot_ax1.plot(self.diff_3[:,0],self.diff_3[:,1], zorder=4)
plot_ax1.grid(b=True, which='major', axis='both', c='0.75', ls='-', linewidth=1)

更多信息:在这里这里

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在Matlab中绘制不同间距的网格线

来自分类Dev

在 Mathematica 中绘制多条网格线并给出单独的标签

来自分类Dev

在python中的点之间绘制网格线

来自分类Dev

在Cartopy地图中绘制网格线

来自分类Dev

在SecondaryAxis上绘制网格线-Matplotlib

来自分类Dev

jQuery在元素上绘制网格线

来自分类Dev

如何绘制比例缩放的网格线?

来自分类Dev

以可变的相交线绘制对角网格线

来自分类Dev

避免PHPExcel中的网格线

来自分类Dev

pcolormesh中的1像素网格线

来自分类Dev

远程桌面中的网格线

来自分类Dev

如何使图表中的网格线静态

来自分类Dev

在Excel PivotChart中调整网格线

来自分类Dev

JavaFx 2.x:如何绘制较小的网格线

来自分类Dev

d3-在指定位置绘制网格线

来自分类Dev

如何仅使用pcolor / pcolormesh绘制网格线

来自分类Dev

如何启用/绘制JointJS图的网格线

来自分类Dev

如何在绘图后使用grid()绘制网格线?

来自分类Dev

如何仅在区域内绘制网格线

来自分类Dev

如何绘制具有相对距离的水平网格线?

来自分类Dev

更改 ggplot2 中次要网格线的数量(每个主要网格线),r

来自分类Dev

调整Matplotlib imshow中的网格线和刻度线

来自分类Dev

简单数据注释验证未显示在“视图”中(无红色网格线)

来自分类Dev

网格线仅位于数据点上的数据点

来自分类Dev

如何在 Matlab 中用空 gridsquares 绘制网格(即显示网格线)

来自分类Dev

替换gtable中ggplot的元素:标签和网格线

来自分类Dev

如何在TreeTableView中显示行的网格线

来自分类Dev

如何从Flot图表中删除网格线

来自分类Dev

iOS 8.1中带有网格线的核心图

Related 相关文章

热门标签

归档