Skip to content

Commit

Permalink
Finished unit test for timedelta plotting.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgoppert committed Jan 14, 2017
1 parent 41ebc85 commit 91954bd
Showing 1 changed file with 40 additions and 7 deletions.
47 changes: 40 additions & 7 deletions pandas/tests/plotting/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -1272,16 +1272,49 @@ def test_plot_outofbounds_datetime(self):
values = [datetime(1677, 1, 1, 12), datetime(1677, 1, 2, 12)]
self.plt.plot(values)

def test_format_timedelta_ticks(self):
def test_format_timedelta_ticks_narrow(self):
import matplotlib.pyplot as plt
rng = timedelta_range('0', periods=3, freq='ns')

expected_labels = [
'00:00:00.00000000{:d}'.format(i)
for i in range(10)]

rng = timedelta_range('0', periods=10, freq='ns')
df = DataFrame(np.random.randn(len(rng), 3), rng)
ax = df.plot()
ax = df.plot(fontsize=2)
ax.get_figure().canvas.draw()
plt.gcf().autofmt_xdate()
xaxis = ax.get_xaxis()
for l in xaxis.get_ticklabels():
if len(l.get_text()) > 0:
self.assertEqual(l.get_rotation(), 30)
labels = ax.get_xticklabels()
self.assertEqual(len(labels), len(expected_labels))
for l, l_expected in zip(labels, expected_labels):
self.assertEqual(l.get_text(), l_expected)
self.assertEqual(l.get_rotation(), 30)

def test_format_timedelta_ticks_wide(self):
import matplotlib.pyplot as plt

expected_labels = [
'00:00:00',
'1 days 03:46:40',
'2 days 07:33:20',
'3 days 11:20:00',
'4 days 15:06:40',
'5 days 18:53:20',
'6 days 22:40:00',
'8 days 02:26:40',
''
]

rng = timedelta_range('0', periods=10, freq='1 d')
df = DataFrame(np.random.randn(len(rng), 3), rng)
ax = df.plot(fontsize=2)
ax.get_figure().canvas.draw()
plt.gcf().autofmt_xdate()
labels = ax.get_xticklabels()
self.assertEqual(len(labels), len(expected_labels))
for l, l_expected in zip(labels, expected_labels):
self.assertEqual(l.get_text(), l_expected)
self.assertEqual(l.get_rotation(), 30)

def test_timedelta_plot(self):
# test issue #8711
Expand Down

0 comments on commit 91954bd

Please sign in to comment.