Navigation Menu

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

axisartist incompatible with autofmt_xdate #602

Closed
ukch opened this issue Dec 1, 2011 · 5 comments
Closed

axisartist incompatible with autofmt_xdate #602

ukch opened this issue Dec 1, 2011 · 5 comments

Comments

@ukch
Copy link

ukch commented Dec 1, 2011

Compare the results of the following two code samples:

from pylab import *

fig = figure()
ax = fig.add_subplot(111)
ax.bar(range(3), [10, 20, 30])
ax.set_xticks(range(3))
ax.set_xticklabels(["supercalifragilisticexpialidocious",
                    "eventhoughthesoundofitissomethingquiteatrocious",
                    "ifyousayitloudenoughyouresuretosoundprecocious"])
fig.autofmt_xdate()
show()
from pylab import *
import mpl_toolkits.axisartist as AA

fig = figure()
ax = fig.add_subplot(AA.Subplot(fig, 111))
ax.bar(range(3), [10, 20, 30])
ax.set_xticks(range(3))
ax.set_xticklabels(["supercalifragilisticexpialidocious",
                    "eventhoughthesoundofitissomethingquiteatrocious",
                    "ifyousayitloudenoughyouresuretosoundprecocious"])
fig.autofmt_xdate()
show()

(The only difference between the samples is that the second one is using mpl_toolkits.axisartist)

The first example formats the tick labels so that they appear diagonally and thus do not overlap each other. The second does not.

I noticed on the AxisGrid page (http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/index.html) the following message:

axes_grid and axisartist (but not axes_grid1) uses a custom Axes class (derived from the mpl’s original Axes class). As a side effect, some commands (mostly tick-related) do not work. Use axes_grid1 to avoid this, or see how things are different in axes_grid and axisartist (LINK needed)

Although this describes a problem simoilar to the one I'm seeing, it is not very helpful as it does not suggest any alternatives. (For the record, I am using axisartist so that I can configure the shape/colour of the axis border)

@WeatherGod
Copy link
Member

autofmt_xdate() is a beast of its own and has plagued us for quite awhile. The issue that is raised in the axes_grid docs is only tangentally related to the issue you are facing here, I think. See pull #1. As far as I know, no change was ever made, but who knows with all of the massive merges caused by the py3k stuff.

@leejjoon
Copy link
Contributor

leejjoon commented Dec 2, 2011

Basically, what "autofmt_xdate" does is to adjust the horizontal-alignment and rotation of texts.
So, here is a workaround you may use.

def axisartist_autofmt_xdate(ax):
    ax.axis["bottom"].major_ticklabels.set_rotation(30)
    ax.axis["bottom"].major_ticklabels.set_ha("right")

axisartist_autofmt_xdate(ax)

With v1.1 of matplotlib, you may optionally do after above

tight_layout()

@ukch
Copy link
Author

ukch commented Dec 2, 2011

Thanks. That seems to work. I am using it in combination with figure.subplots_adjust(bottom=0.2) to achieve similar results.

@efiring
Copy link
Member

efiring commented May 29, 2013

@leejjoon, does this issue need to stay open?

@leejjoon
Copy link
Contributor

I believe we can close it.

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

No branches or pull requests

4 participants