Skip to content

axvspan() sometimes breaks when using matplotlib wrappers #5092

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

Closed
darothen opened this issue Oct 3, 2013 · 3 comments
Closed

axvspan() sometimes breaks when using matplotlib wrappers #5092

darothen opened this issue Oct 3, 2013 · 3 comments
Labels

Comments

@darothen
Copy link

darothen commented Oct 3, 2013

Hi,

I was trying to highlight some data in a DataFrame using the axvspan method from matplotlib and I ran into some ill behavior. Here's a minimal example:

import numpy as np
import pandas as pd
import matplotlib.dates as mdates

from pylab import *
ion()

dates = pd.date_range(start="10/01/2013", end="10/04/2013", freq='H')
data = np.random.random_sample(len(dates))

my_df = pd.DataFrame({'r': data}, index=dates)

figure()
my_df.plot()
axvspan(*mdates.datestr2num(["10/02/2013", "10/03/2013"]),
             facecolor='red', alpha=0.5)

This produces the following figure:

vspan_test_bad

However, when I instead invoke the plotter via my_df.plot(x_compat=True), things are kosher:

vspan_test_good

save for the fact that the advanced x-axis formatting has been lost (easy enough to replace). I'm not sure if this is an unintended feature or a bug, but it's not documented anywhere.

@selasley
Copy link
Contributor

selasley commented Oct 3, 2013

I had a similar problem recently and found that passing datetimes into axvspan works. So

axvspan(*pd.to_datetime(["10/02/2013", "10/03/2013"]),
facecolor='red', alpha=0.5)

works with my_df.plot() and my_df.plot(x_compat=True)

@jreback
Copy link
Contributor

jreback commented Oct 8, 2013

closing as not a bug

@jreback jreback closed this as completed Oct 8, 2013
@michaelaye
Copy link
Contributor

This should be advertised better, extremely important feature!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants