changing the axis tick frequency

4,597 views
Skip to first unread message

Niall Robinson

unread,
Feb 21, 2013, 11:02:32 AM2/21/13
to scitoo...@googlegroups.com
Hello - I've got a seemingly very simple problem that I can't solve. When I iplt.plot a cube the years overlap. How can i set the frequency of ticks to be lower so that this doesn't happen.

Thanks
Niall

Phil Elson

unread,
Feb 22, 2013, 10:04:30 AM2/22/13
to scitoo...@googlegroups.com
Hi Niall,

This isn't really an Iris question - its more a matplotlib one. I haven't tested this, but my guess would be to do:

import matplotlib.pyplot as plt
plt.locator_params(axis = 'x', nbins = 4)

After your plot. I found this solution on StackOverflow (http://stackoverflow.com/questions/6682784/how-to-reduce-number-of-ticks-with-matplotlib), but if it doesn't work, I'd be happy to look into it further.

HTH


Niall Robinson

unread,
Feb 25, 2013, 6:43:38 AM2/25/13
to scitoo...@googlegroups.com
Hi Phil,

I probably should have given you more information. I tried that, but I get this error
Traceback (most recent call last):
 
File "<console>", line 1, in <module>
 
File "/usr/local/sci/lib/python2.7/site-packages/matplotlib/pyplot.py", line 3252, in locator_params
    ret
= gca().locator_params(axis=axis, tight=tight, **kwargs)
 
File "/usr/local/sci/lib/python2.7/site-packages/matplotlib/axes.py", line 2312, in locator_params
   
self.xaxis.get_major_locator().set_params(**kwargs)
AttributeError: 'AutoDateLocator' object has no attribute 'set_params'

so I wondered if there was a specific iris way of doing it. I guess its a bit different to matplotlib as (on the surface) you don't start with an x,y pair

Susan

unread,
Mar 1, 2013, 3:36:48 AM3/1/13
to scitoo...@googlegroups.com
Hi Niall,

I had a similar problem with overlapping dates - hours and days in my case rather than years but I guess the solution is similar.
I'm now specifying the interval between the tick marks rather than the number of tick marks:

from matplotlib.dates import HourLocator, DayLocator, DateFormatter

days
= DayLocator(interval=1)
hours
= HourLocator(interval=6)
daysFmt
= DateFormatter('%d')
plt
.gca().xaxis.set_major_locator(days)
plt
.gca().xaxis.set_major_formatter(daysFmt)
plt
.gca().xaxis.set_minor_locator(hours)

Hope that helps,

Susan

Niall Robinson

unread,
Mar 4, 2013, 4:18:53 AM3/4/13
to scitoo...@googlegroups.com
Ah brilliant - thanks
Reply all
Reply to author
Forward
0 new messages