简体   繁体   English

Matplotlib axvspan-固体填充吗?

[英]Matplotlib axvspan - solid fill?

I'm using this line of code to create a vertical span across a graph using matplotlib. 我正在使用这一行代码使用matplotlib在图形上创建垂直跨度。

matplotlib.pyplot.axvspan(datetime.datetime.strptime("09-10-2015", '%d-%m-%Y'), datetime.datetime.strptime(now.strftime("%d-%m-%Y"), '%d-%m-%Y'), fill=True, linewidth=0, color='r')

However I'd like it to go over the graph to hide the line on the graph. 但是,我希望它遍历图形以隐藏图形上的线。 At the moment it just does this. 目前,它只是这样做。

在此处输入图片说明

How can I make the fill of this axvspan solid and non transparent? 如何使此axvspan的填充实心且不透明?

It's not about transparency (which you can change with the alpha parameter). 这与透明度(您可以使用alpha参数更改)无关。 It's about zorder (a kind of distance to the user, lower zorder will be farther). 这是关于zorder (与用户的距离,较低的zorder会更远)。 You need to put the zorder of the grid below the zorder of the axvspan (which in turn should be below, I think, of the plot ). 您需要将grid的zorder放置在axvspan的zorder axvspan (我认为,后者应位于该plot )。 Check the following example: 检查以下示例:

import numpy as np
import matplotlib.pyplot as plt

t = np.arange(-1, 2, .01)
s = np.sin(2*np.pi*t)

plt.plot(t, s,zorder=4)

p = plt.axvspan(1.25, 1.55, facecolor='g', alpha=1,zorder=3)

plt.axis([-1, 2, -1, 2])
plt.grid(zorder=2)

plt.show()

, which results in: ,结果为:

matplotlib图中元素的Zorder

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM