python - 布林带阴影没有颜色阴影
问题描述
我试图在代表“上带”和“下带”的上红线和下橙线之间加阴影
我得到了这张图片:
我试过的代码如下:
fig = plt.figure()
plt.plot(dataset[['Adj Close', 'ma21', 'upper_band', 'lower_band']])
plt.fill_between(dataset.index, dataset['upper_band'], dataset['lower_band'], color='grey', alpha = 0.3)
plt.legend(loc='best')
plt.savefig('bollinger.png')
plt.show()
我相信它与有关,dataset.index
但我不确定如何正确获取 x 轴。
谢谢。
解决方案
您可以使用此处找到的文档并使用matplotlib.pyplot.fill_between
方法
这是一个使用它的例子:
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0.0, 2, 0.01)
y1 = np.sin(2 * np.pi * x)
y2 = 0.8 * np.sin(4 * np.pi * x)
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, sharex=True, figsize=(6, 6))
ax3.fill_between(x, y1, y2)
ax3.set_title('fill between y1 and y2')
ax3.set_xlabel('x')
fig.tight_layout()
推荐阅读
- c# - 如何以编程方式从动态 JObject 中删除属性
- c# - 实体框架 - SaveChanges 与事务
- php - 如何过滤 wordpress the_date() 和 get_the_date() 函数以仅显示帖子发布的年份
- .net-core - Abp中如何使用EfCore Code First将实体中的注解生成到数据库的字段描述中
- linux - 如何修复 java.sql.SQLNonTransientException:java.sql.SQLNonTransientException:null DSRA0010E:SQL 状态 = 08001,错误代码 = -1,639 错误
- macos - 是否有可能在 MacOS v < 11 上获得 Apple Developer Id
- javascript - 由于无法使用 app.listen,如何使用使用 npm create-react-app 制作的 React 应用程序实现 Express.js?
- python - 如何在 Pandas 中使用向量对矩阵执行布尔与运算?
- json - 如何按特定字段中的 Json 字符串列过滤数据
- android - 如何在不使用 Mainacitivity 的情况下先显示我的启动画面