我最近遇到了plotly,这是一个非常强大的交互式在线绘图系统。所以我正在考虑将matplot生成的图转换为plotly。除了时间序列图,一切都很好。
这是我的代码的简单版本。
import pandas as pd
import matplotlib.pyplot as plt
import plotly.plotly as py
import plotly.tools as tls
tls.set_credentials_file(
username="edwinwang1988",
api_key="o8xw6s61dn")
import numpy as np
x = pd.date_range('1/1/2001',periods =72,freq='D') # genrate a date range
Series = pd.DataFrame(x,columns=['Date']) # generate a date range data frame
np.random.seed(0)
col = ['A','B','C','D'] #set col names for return series
s = pd.DataFrame(np.random.randn(72,4),columns=col) # generate random return series with col names as col
for i in range(len(col)):
s[col[i]] = s[col[i]].cumsum()
s['Date']=x # add date to dataframe s
s.plot(x='Date') # plot s and set date as x axis
这工作正常,并给我我想要的日期作为 x 轴的情节。但是当我试图将数字转换为 plotly 时。
mpl_fig2= plt.gcf()
py.iplot_mpl(mpl_fig2,strip_styple = True,filename='test')
我看到像“min() arg is an empty sequence”这样的代码错误,有时这个“year=1 在 1900 之前;datetime strftime() 方法需要 year >= 1900”