【发布时间】:2015-01-06 04:07:42
【问题描述】:
我最近遇到了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”
【问题讨论】:
标签: python-2.7 matplotlib plotly