python - 透明的“覆盖”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)
推荐阅读
- java - 如何使用 JPA 注释双 varchar 主键?
- c - 我无法将 argc 和 argv 从命令行获取到函数调用中
- php - 无法使用 httpClient 将字符串上传到我的 SSL 服务器
- mysql - 如何使用一个自动生成的值创建复合主键?
- node.js - Node.Js、express、res.sendFile 无法建立根目录
- python - 使用 re.match() 查找以两个可能的字母开头的字符串
- python - 在网络服务器上运行的 Flask 应用程序以调用远程服务器 python 模块
- javascript - 将大写字母转换为小写字母,将小写字母转换为大写字母
- docker - 尝试使用 grpc 连接到 docker 容器时出错
- python - time.get_clock_info().resolution 的含义