Python and plot() : how to limit the number of x-axis ticks (labels)


I have two lists, same size, one is y_data and one is x_data x_data is a time hh:mm:ss during day, in fact each minute each serie is 1440 long.

problem is :

fig = Figure(figsize=(4,3))
a = gif.add_subplot(111)
a.plot(x_data, y_data)

give an unreadable x_axis (too many labels), if i reduce x_data to [range(24)] for instance, plot gives an error.

Question :

I'd like to have only 24 items on x_axis scale (each hour, so 1 item each 60 x_data points) is there a simple way to achieve this ? set_autoscale_on(False) and then manually setting limits seems a very complex way to achieve this (and I would loose the benefits from autoscaling on y axis). Another solution seems to involve a.xaxis.set_ticks() but i have to crate a new serie.

o I'd like to use x_data but just limit the number of ticks shown on x_axis, is there a way to do it ?

2/27/2015 11:21:15 AM

The pyplot interface of matplotlib provides a function locator_params, where you can set this option:

fig = Figure(figsize=(4,3))
a = fig.add_subplot(111)
a.plot(x_data, y_data)
12/16/2011 12:05:55 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow