File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
plotly/tests/test_optional/test_matplotlylib Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 11from __future__ import absolute_import
2+
3+ import random
24import matplotlib
35# Force matplotlib to not use any Xwindows backend.
46matplotlib .use ('Agg' )
57import matplotlib .pyplot as plt
68import datetime
79from matplotlib .dates import date2num
10+ import pandas as pd
811import plotly .tools as tls
912from unittest import TestCase
1013
@@ -41,3 +44,24 @@ def test_normal_mpl_dates(self):
4144 fig .axes [0 ].lines [0 ].get_xydata ()[0 ][0 ], 7.33776000e+05
4245 )
4346 self .assertEqual (pfig ['data' ][0 ]['x' ], date_strings )
47+
48+ def test_pandas_time_series_date_formatter (self ):
49+ ndays = 3
50+ x = pd .date_range ('1/1/2001' , periods = ndays , freq = 'D' )
51+ y = [random .randint (0 , 10 ) for i in range (ndays )]
52+ s = pd .DataFrame (y , columns = ['a' ])
53+
54+ s ['Date' ] = x
55+ s .plot (x = 'Date' )
56+
57+ fig = plt .gcf ()
58+ pfig = tls .mpl_to_plotly (fig )
59+
60+ expected_x = ['2001-01-01 00:00:00' ,
61+ '2001-01-02 00:00:00' ,
62+ '2001-01-03 00:00:00' ]
63+ expected_x0 = 11323.0 # this is floating point days since epoch
64+
65+ x0 = fig .axes [0 ].lines [0 ].get_xydata ()[0 ][0 ]
66+ self .assertEqual (x0 , expected_x0 )
67+ self .assertListEqual (pfig ['data' ][0 ]['x' ], expected_x )
You can’t perform that action at this time.
0 commit comments