Skip to content

Commit 2ccf301

Browse files
committed
BUG: fixing tseries plot cursor display, resolves #5453
1 parent 1827abd commit 2ccf301

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

doc/source/release.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,9 @@ Bug Fixes
450450
- Bug in enabling ``subplots=True`` in ``DataFrame.plot`` only has single column raises ``TypeError``, and ``Series.plot`` raises ``AttributeError`` (:issue:`6951`)
451451
- Bug in ``DataFrame.plot`` draws unnecessary axes when enabling ``subplots`` and ``kind=scatter`` (:issue:`6951`)
452452
- Bug in ``read_csv`` from a filesystem with non-utf-8 encoding (:issue:`6807`)
453-
- Bug in ``iloc`` when setting / aligning (:issue:``6766`)
453+
- Bug in ``iloc`` when setting / aligning (:issue:`6766`)
454454
- Bug causing UnicodeEncodeError when get_dummies called with unicode values and a prefix (:issue:`6885`)
455+
- Bug in timeseries-with-frequency plot cursor display (:issue:`5453`)
455456

456457
pandas 0.13.1
457458
-------------

pandas/tseries/plotting.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ def tsplot(series, plotf, **kwargs):
8383
ax.set_xlim(left, right)
8484

8585
# x and y coord info
86-
tz = series.index.to_datetime().tz
87-
ax.format_coord = lambda t, y : "t = {} y = {:8f}".format(datetime.fromtimestamp(t, tz), y)
86+
ax.format_coord = lambda t, y: "t = {} y = {:8f}".format(Period(ordinal=int(t), freq=ax.freq), y)
8887

8988
return lines
9089

pandas/tseries/tests/test_plotting.py

+15
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,21 @@ def test_get_datevalue(self):
131131
self.assertEqual(get_datevalue('1/1/1987', 'D'),
132132
Period('1987-1-1', 'D').ordinal)
133133

134+
@slow
135+
def test_ts_plot_format_coord(self):
136+
def check_format_of_first_point(ax, expected_string):
137+
first_line = ax.get_lines()[0]
138+
first_x = first_line.get_xdata()[0].ordinal
139+
first_y = first_line.get_ydata()[0]
140+
self.assertEqual(expected_string, ax.format_coord(first_x, first_y))
141+
142+
annual = Series(1, index=date_range('2014-01-01', periods=3, freq='A-DEC'))
143+
check_format_of_first_point(annual.plot(), 't = 2014 y = 1.000000')
144+
145+
# note this is added to the annual plot already in existence, and changes its freq field
146+
daily = Series(1, index=date_range('2014-01-01', periods=3, freq='D'))
147+
check_format_of_first_point(daily.plot(), 't = 2014-01-01 y = 1.000000')
148+
134149
@slow
135150
def test_line_plot_period_series(self):
136151
for s in self.period_ser:

0 commit comments

Comments
 (0)