Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: matplotlib invert_xaxis crashes when using datetime #3990

jorisvandenbossche opened this issue Jun 22, 2013 · 1 comment


None yet
2 participants
Copy link

commented Jun 22, 2013

From stackoverflow, a question from more than a month ago, but still an issue I think (tested with master).

Basicly, when using ax.invert_xaxis() with datetime x-values, the following exception is raised:

RuntimeError: MillisecondLocator estimated to generate 5270400 ticks from 2012-08-01 00:00:00+00:00 to 2012-10-01 00:00:00+00:00: 
exceeds Locator.MAXTICKS* 2 (2000)

At first it may not seem an error from pandas, as you can trigger it by using pure matplotlib code, but the error comes from pandas\tseries\ And more, it is by importing pandas that causes working matplotlib code to work no longer:

import numpy as np
import matplotlib.pyplot as plt
import datetime

x = np.array([datetime.datetime(2012, 8, 1, 0, 0),
              datetime.datetime(2012, 9, 1, 0, 0),
              datetime.datetime(2012, 10, 1, 0, 0)], dtype=object)
y = np.array([-1,0,1])

## Working matplotlib!
fig, ax = plt.subplots()

import pandas as pd

## Same matplotlib not working anymore after importing pandas
fig, ax = plt.subplots()

CAUSE of the bug:
When using ax.invert_xaxis() the left and right xlim are interchanged. Because of this the delta in PandasAutoDateLocator will be negative (
This in turn triggers MilliSecondLocator instead of the normal AutoDateLocator, and causes the error as the datetime range is too big for MilliSecondLocator.

What I don't understand is why this is not happening when using pandas plot to create the axes object (the workaround I gave at stackoverflow):

df = pd.DataFrame(y, index=x, columns=['test'])

## This works as expected!
fig, ax = plt.subplots()

jorisvandenbossche added a commit to jorisvandenbossche/pandas that referenced this issue Jul 10, 2013

jreback added a commit that referenced this issue Jul 10, 2013

Merge pull request #3991 from jorisvandenbossche/bug_invert_xaxis
BUG: invert_xaxis (negative tot_sec) triggers MilliSecondLocator (#3990)

This comment has been minimized.

Copy link

commented Jul 10, 2013

closed via #3991

@jreback jreback closed this Jul 10, 2013

yarikoptic added a commit to neurodebian/pandas that referenced this issue Jul 25, 2013

Merge commit 'v0.12.0rc1-43-g7b2eaa4' into debian
* commit 'v0.12.0rc1-43-g7b2eaa4': (571 commits)
  PERF: add ix scalar get benchmark
  DOC: more prominent HDFStore store docs about storer/table formats
  BUG: invert_xaxis (negative tot_sec) triggers MilliSecondLocator (pandas-dev#3990)
  BUG: (GH4192) fixed broken unit test
  BUG: (GH4192) Fixed buglet in the broadcasting logic in Series.where
  CLN: Ignore warnings generated by 'DROP TABLE IF EXISTS' when table does not exist.
  DOC: more cookbook recipies
  DOC: update ipython_directive with changes from ipython to restart prompt number at 1 each page
  DOC: increased width of text area
  TST: fix ujson tests failures on 32-bit
  TST: raise when no data are found when trying to dld multiple symbols
  TST: Create a MySQL database and run MySQL tests on Travis.
  CLN: write the attributes in a HDFStore as strings
  TST: remove double call to yahoo finance
  DOC to_datetime warning about dayfirst strictness
  TST: to_datetime format fixes
  DOC: minor io/whatsnew doc edits
  BUG/TST: wrong parsing of microseconds with format arg (pandas-dev#4152)
  RLS: first release candidate for v0.12.0
  BLD: use the wheel url for scikits timeseries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.