Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e47bc04

Browse files
author
Kyle Bridgemohansingh
committed
This commit should solve issue #5575 by ensuring that plot_date first updates the units with the right timezone, before actually plotting the dates. Includes tests to ensure consistency and correctness
1 parent 3ba9279 commit e47bc04

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,13 +1492,13 @@ def plot_date(self, x, y, fmt='o', tz=None, xdate=True, ydate=False,
14921492
if not self._hold:
14931493
self.cla()
14941494

1495-
ret = self.plot(x, y, fmt, **kwargs)
1496-
14971495
if xdate:
14981496
self.xaxis_date(tz)
14991497
if ydate:
15001498
self.yaxis_date(tz)
15011499

1500+
ret = self.plot(x, y, fmt, **kwargs)
1501+
15021502
self.autoscale_view()
15031503

15041504
return ret

lib/matplotlib/tests/test_axes.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
import datetime
1313

14+
import pytz
15+
1416
import numpy as np
1517
from numpy import ma
1618
from numpy import arange
@@ -4335,6 +4337,55 @@ def test_pandas_indexing_hist():
43354337
fig, axes = plt.subplots()
43364338
axes.hist(ser_2)
43374339

4340+
@image_comparison(baseline_images=['date_timezone_x'], extensions=['png'])
4341+
def test_date_timezone_x():
4342+
# Tests issue 5575
4343+
time_index = [pytz.timezone('Canada/Eastern').localize(datetime.datetime(
4344+
year=2016, month=2, day=22, hour=x)) for x in range(3)]
4345+
4346+
# Same Timezone
4347+
fig = plt.figure(figsize=(20, 12))
4348+
plt.subplot(2, 1, 1)
4349+
plt.plot_date(time_index, [3] * 3, tz='Canada/Eastern')
4350+
4351+
# Different Timezone
4352+
plt.subplot(2, 1, 2)
4353+
plt.plot_date(time_index, [3] * 3, tz='UTC')
4354+
4355+
4356+
@image_comparison(baseline_images=['date_timezone_y'],
4357+
extensions=['png'])
4358+
def test_date_timezone_y():
4359+
# Tests issue 5575
4360+
time_index = [pytz.timezone('Canada/Eastern').localize(datetime.datetime(
4361+
year=2016, month=2, day=22, hour=x)) for x in range(3)]
4362+
4363+
# Same Timezone
4364+
fig = plt.figure(figsize=(20, 12))
4365+
plt.subplot(2, 1, 1)
4366+
plt.plot_date([3] * 3,
4367+
time_index, tz='Canada/Eastern', xdate=False, ydate=True)
4368+
4369+
# Different Timezone
4370+
plt.subplot(2, 1, 2)
4371+
plt.plot_date([3] * 3, time_index, tz='UTC', xdate=False, ydate=True)
4372+
4373+
4374+
@image_comparison(baseline_images=['date_timezone_x_and_y'],
4375+
extensions=['png'])
4376+
def test_date_timezone_x_and_y():
4377+
# Tests issue 5575
4378+
time_index = [pytz.timezone('UTC').localize(datetime.datetime(
4379+
year=2016, month=2, day=22, hour=x)) for x in range(3)]
4380+
4381+
# Same Timezone
4382+
fig = plt.figure(figsize=(20, 12))
4383+
plt.subplot(2, 1, 1)
4384+
plt.plot_date(time_index, time_index, tz='UTC', ydate=True)
4385+
4386+
# Different Timezone
4387+
plt.subplot(2, 1, 2)
4388+
plt.plot_date(time_index, time_index, tz='US/Eastern', ydate=True)
43384389

43394390
if __name__ == '__main__':
43404391
import nose

0 commit comments

Comments
 (0)