Matplotlib, shared axes and formatters

February 6, 2010 at 7:35 pm Leave a comment

I Just spent quarter of an hour or so being perplexed an annoyed by matplotlib.

It turns out that if you use the sharex property when creating subplots, plotting on these later plots will override any
previous formatter set on the other plots. (This in a way makes sense – since all the plots axes must be redrawn to take account of the facts that the axis might have grown).

This means that if you want to set a formatter (or a tick locator) this must be done after the final plot that shares an axis.

Bad:

plot1 = subplot(121)
plot(stuff)
gca().xaxis.set_major_formatter(CrazyFormatter)

subplot(122, sharex=plot1)
plot(other_stuff) # destroys the first formatter

Good:

plot1 = subplot(121)
plot(stuff)

subplot(122, sharex=plot1)
plot(other_stuff) # destroys the first formatter
gca().xaxis.set_major_formatter(CrazyFormatter)

Relevant links:

Ticker api
Pyplot api

Advertisements

Entry filed under: Uncategorized.

Nvidia twinview – changing the screen order Multiple recursive many-to-many relationships in djangos ORM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


February 2010
M T W T F S S
« Jan   Mar »
1234567
891011121314
15161718192021
22232425262728

%d bloggers like this: