[Matplotlib-users] Autoscaling Date Locator with minor ticks?
tcaswell at gmail.com
Sat May 25 21:11:22 EDT 2019
Setting the minor and major locators in the correct approach, but you need
to set them with different settings (as other wise they will decide to put
the ticks at the sameplaces, hence the "doubled" labels. This behavior
changed with 3.1 (see
and going forward the overlapping minor ticks will be trimmed by default).
I suspect that by playing with `minticks` and `maxticks` you can get the
effect you want:
import numpy as np
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
t = np.arange("2018-11-03", "2018-11-06", dtype="datetime64")
x = np.random.rand(len(t))
fig, ax = plt.subplots()
You may also be interested in the ConciseDateFormatter (
https://matplotlib.org/users/whats_new.html#concisedateformatter ) that is
new in 3.1.
On Fri, May 3, 2019 at 9:16 PM Akkana Peck <akkana at shallowsky.com> wrote:
> Is there any way to get AutoDateLocator to handle minor ticks as
> well as major ones?
> For instance, if I have a plot spanning a few days, I'd like to be
> able to show the date as a label and major tick, but show minor
> ticks for hours, or one minor tick every six hours, whatever is
> sensible depending on the scale. Or on a plot spanning a few years,
> show labels for each year, but with 12 minor ticks showing months.
> It seems like AutoDateLocator only draws major ticks.
> I can write a custom date locator that handles the minor ticks
> nicely, but then I don't get the nice auto-scaling of
> AutoDateLocator, and if I plot a larger or smaller date range,
> my labels and ticks become too crowded or too sparse.
> I tried setting both major and minor locators to AutoDateLocators:
> and similarly with set_*_formatter(), but that just gave me
> smeary-looking double-printed major labels and ticks.
> Maybe I need to write a custom smart locator that reproduces
> AutoDateLocator's auto-scaling while also handling ticks. But before
> I dive into that, I thought I'd ask; I can't be the only person who
> needs more precise ticks and labeling than AutoDateLocator provides.
> Matplotlib-users mailing list
> Matplotlib-users at python.org
tcaswell at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Matplotlib-users