首页 > 解决方案 > Exclude x window using matplotlib fill_between

问题描述

I am trying to exclude a x window range in plot using fill_between. Excluding a one sided range doing

x=np.linspace(1,100)    
plt.fill_between(x, -1, 1, alpha = 0.1, linewidth=0, facecolor='green', hatch='/////////', where= x<20)

will work and produce:

enter image description here

However if I just want to exclude a range x in [40, 60] using

plt.fill_between(x, -1, 1, alpha = 0.1, linewidth=0, facecolor='green', hatch='/////////', where= x<20 and x>60)

will not work with the error

The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

However, using any() or all() does not lead to the desired result. What is the recommended way of doing this?

标签: pythonpython-3.xmatplotlib

解决方案


推荐阅读