Tuesday 15 February 2011

python 2.7 - convert time series plot using matplot to plotly -



python 2.7 - convert time series plot using matplot to plotly -

i come across plotly powerful interactive online plot system. thinking converting plots generated matplot plotly. works fine except time series plot.

here simple version of code.

import pandas pd import matplotlib.pyplot plt import plotly.plotly py import plotly.tools tls tls.set_credentials_file( username="edwinwang1988", api_key="o8xw6s61dn") import numpy np x = pd.date_range('1/1/2001',periods =72,freq='d') # genrate date range series = pd.dataframe(x,columns=['date']) # generate date range info frame np.random.seed(0) col = ['a','b','c','d'] #set col names homecoming series s = pd.dataframe(np.random.randn(72,4),columns=col) # generate random homecoming series col names col in range(len(col)): s[col[i]] = s[col[i]].cumsum() s['date']=x # add together date dataframe s s.plot(x='date') # plot s , set date x axis

this works fine , give me plot want date x axis. when tried convert figure plotly.

mpl_fig2= plt.gcf() py.iplot_mpl(mpl_fig2,strip_styple = true,filename='test')

i seeing code error "min() arg empty sequence" , "year=1 before 1900; datetime strftime() methods require year >= 1900"

full disclosure, work plotly.

tl;dr:

run in terminal , should fixed:

pip install --upgrade plotly

context:

so, pandas can funny things dates in matplotlib. how matplotlib handles dates, basically:

day 1 of year 1 in utc floating point 1.0

http://matplotlib.org/api/dates_api.html#module-matplotlib.dates

depending on how utilize pandas format dates, can end pandas timeseries_dateformatter. best of knowledge, repercussion of alter underlying info associated date times next convention:

day 1 of year 1970 in utc floating point 0.0

so, days (not seconds!) since epoch (http://en.wikipedia.org/wiki/unix_time). fyi, goes ~9-22-1677 using negative numbers.

issue:

plotly treating datetimes within matplotlib matplotlib datetimes, pandas adds formatter changes this. patch added in plotly 1.4.2

python-2.7 matplotlib plotly

No comments:

Post a Comment