透明 "overlay" matplotlib stackplot
transparatent "overlay" matplotlib stackplot
我有一个简单的堆栈图:
import matplotlib.pyplot as plt
label, color = ["R", "M"], ["green", "blue"]
X = [x for x in range(101)]
Y1 = [31.4*x for x in range(101)]
Y2 = [26.51*x-250 if (26.51*x-250)>=0 else 0 for x in range(101)]
Y3 = [31.4*x if 31.4*x < 2400 else 2400 for x in range(101)]
plt.stackplot(X, Y1, Y2, labels=label, colors = color)
plt.fill_between(X,Y3,[2400 for x in range(101)], color = 'r')
plt.legend(loc=2)
plt.xlim(0,100)
plt.ylim(0,5600)
plt.show()
可能有更好的方法来显示我想显示的内容,但我只想知道如何在可能的情况下使用matplotlib 使红色区域透明。
如果我没理解错的话,你需要像下面这样的东西吗?
在这种情况下,您可以指定 fill_between
的透明度
import matplotlib.pyplot as plt
label, color = ["R", "M"], ["green", "blue"]
X = [x for x in range(101)]
Y1 = [31.4*x for x in range(101)]
Y2 = [26.51*x-250 if (26.51*x-250)>=0 else 0 for x in range(101)]
Y3 = [31.4*x if 31.4*x < 2400 else 2400 for x in range(101)]
plt.stackplot(X, Y1, Y2, labels=label, colors = color)
plt.fill_between(X,Y3,[2400 for x in range(101)], color = 'r', alpha=0.3)
plt.legend(loc=2)
plt.xlim(0,100)
plt.ylim(0,5600)
我有一个简单的堆栈图:
import matplotlib.pyplot as plt
label, color = ["R", "M"], ["green", "blue"]
X = [x for x in range(101)]
Y1 = [31.4*x for x in range(101)]
Y2 = [26.51*x-250 if (26.51*x-250)>=0 else 0 for x in range(101)]
Y3 = [31.4*x if 31.4*x < 2400 else 2400 for x in range(101)]
plt.stackplot(X, Y1, Y2, labels=label, colors = color)
plt.fill_between(X,Y3,[2400 for x in range(101)], color = 'r')
plt.legend(loc=2)
plt.xlim(0,100)
plt.ylim(0,5600)
plt.show()
可能有更好的方法来显示我想显示的内容,但我只想知道如何在可能的情况下使用matplotlib 使红色区域透明。
如果我没理解错的话,你需要像下面这样的东西吗?
在这种情况下,您可以指定 fill_between
import matplotlib.pyplot as plt
label, color = ["R", "M"], ["green", "blue"]
X = [x for x in range(101)]
Y1 = [31.4*x for x in range(101)]
Y2 = [26.51*x-250 if (26.51*x-250)>=0 else 0 for x in range(101)]
Y3 = [31.4*x if 31.4*x < 2400 else 2400 for x in range(101)]
plt.stackplot(X, Y1, Y2, labels=label, colors = color)
plt.fill_between(X,Y3,[2400 for x in range(101)], color = 'r', alpha=0.3)
plt.legend(loc=2)
plt.xlim(0,100)
plt.ylim(0,5600)