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 1
1
from __future__ import absolute_import
2
+
3
+ import random
2
4
import matplotlib
3
5
# Force matplotlib to not use any Xwindows backend.
4
6
matplotlib .use ('Agg' )
5
7
import matplotlib .pyplot as plt
6
8
import datetime
7
9
from matplotlib .dates import date2num
10
+ import pandas as pd
8
11
import plotly .tools as tls
9
12
from unittest import TestCase
10
13
@@ -41,3 +44,24 @@ def test_normal_mpl_dates(self):
41
44
fig .axes [0 ].lines [0 ].get_xydata ()[0 ][0 ], 7.33776000e+05
42
45
)
43
46
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