我有一个看起来像这样的情节:
import pandas as pd
import pandas_datareader as web
import datetime as dt
from datetime import timedelta
import matplotlib.pyplot as plt
#get the data
start_date = pd.to_datetime('2019-11-1')
end_date = pd.datetime.today()
df = web.DataReader('^gspc', 'yahoo', start_date, end_date)
df = df['Adj Close']
#build the plot
fig, ax1 = plt.subplots()
ax1.plot(df)
#set the axhline
ax1.axhline(df.max(),xmin=0,xmax=1)
ax1.set_xlim(start_date,end_date + timedelta(30))
ax1.set_ylim(df.min() -200, df.max() +200)
Run Code Online (Sandbox Code Playgroud)
我正在尝试设置 axhline,以便它从 df 中最大值的那一天开始。我遇到问题,因为索引是日期时间对象,而 axhline 需要一个整数。
这是我尝试过的:
ax1.axhline(df.max(),xmin=df.idxmax(),xmax=1)
Run Code Online (Sandbox Code Playgroud)
将 xmin 设置为 df 中最大值的日期的最有效方法是什么?
谢谢
我正在尝试使用 pandas 样式 API 更改标题的字体大小。这可能吗?
这是我到目前为止所拥有的:
import pandas as pd
data = {'col1': [1, 2], 'col2': [3, 4]}
df = pd.DataFrame(data=data)
df.style.set_caption("Some Caption")
Run Code Online (Sandbox Code Playgroud)
感谢任何输入。