nc-time-axis icon indicating copy to clipboard operation
nc-time-axis copied to clipboard

Control max number of ticks

Open lbdreyer opened this issue 8 years ago • 2 comments

Currently, the max number of ticks is set to 4 (on this line). This is a bit restrictive.

It would be nice if the user had control over the number of ticks, perhaps through the use of some kind of set_max_ticks method.

lbdreyer avatar Jul 19 '16 10:07 lbdreyer

I think this would be relatively easy to implement. I'm experienced with python but not with GitHub so I've been toying around with how to contribute a solution to this. In the mean time, if anyone else wants a work around for modifying the number of ticks, here's an example which sets the max number to 7. You can also modify other parameters of matplotlib's MaxNLocator this way.

ax.xaxis.get_major_locator()._max_n_locator.set_params(nbins=7)

Note this only works if the resolution is not daily. If you have daily resolution along the time axis, use

ax.xaxis.get_major_locator()._max_n_locator_days.set_params(nbins=7)

Really it would be great if support is implemented for the set_params() method. This information could be passed onto the MaxNLocator as I am doing here. Then you could make your adjustments using the ax.locator_params from matplotlib. I'm working on such a solution but do not have much time to dedicate, and so I'm leaving this idea here to help collective progress.

sjsmith757 avatar May 01 '20 03:05 sjsmith757

@SciTools/peloton just reviewing this. @sjsmith757 is there any chance of your submitting an attempt at this ? Otherwise we might have to close this down.

pp-mo avatar Mar 29 '23 09:03 pp-mo