python - 用 x 值范围填充 matplotlib 上的 x 和 y 值
问题描述
我正在使用熊猫和 matplotlib。使用某种颜色,我想填充我的 x 轴和价格(又名收盘价)之间的空间。我该怎么办?我是python的初学者。
import datetime as dt
import pandas_datareader.data as web
import matplotlib.pyplot as plt
import pandas as pd
# Defining Axis
fig = plt.figure()
ax1 = plt.subplot2grid((1,1), (0,0))
# Data Section
start = dt.datetime(2017,1,1)
end = dt.datetime(2018,1,1)
sp500 = web.DataReader("TSLA", "yahoo", start, end)
close = sp500['Adj Close']
# Axis Settings Section
ax1.fill_between(start, close, 0, color='grey') #here is where I'm having issues. I think the issues im having partly involve the fact that im dealing with a range of dates
ax1.plot(close, label = 'price')
ax1.grid(True, color= 'lightgreen', linestyle= '-')
ax1.xaxis.label.set_color('dodgerblue')
ax1.yaxis.label.set_color('indianred')
ax1.set_yticks([0,100,200,300,400])
# Graph/Chart Settings
plt.xlabel('Date')
plt.ylabel('Price')
plt.legend()
plt.xticks(rotation=45)
plt.subplots_adjust(left=0.09, bottom=0.20, top=0.90, wspace=0.20, hspace=0.0)
plt.show()
解决方案
推荐阅读
- c# - 使用 ASP.Net Web 应用程序的 DataAnnotation 强制执行身份密码规则
- jdbc - 当我尝试运行 .jar 程序时,无法识别 -classpath 中的 jar 文件
- c# - 获取文件名目录
- java - 依赖列表的 JUnit 测试构造函数注入
- javascript - 如何从 json 中提取与在我的标记中单击的按钮有关的特定数据以 HTML 格式输出?
- python - 单元测试中的 Python AttributeError
- mysql - 如何修复错误“数据库未初始化且未指定密码选项”
- javascript - 角度排气图
- r - 如何用双反斜杠对 R 中的字符串进行编码?
- c# - Identityserver4:端点认证客户端+用户凭证