Can any please explain the behaviour of tickformatstops?
In the example “Time series and date axes in Python”, it says; “The tickformatstops attribute can be used to customize the formatting of tick labels depending on the zoom level.”
In the reference, the ‘dtickrange’ argument defines the “min”, “max” - dtick values which describe some zoom level.
What value needs to be inbetween the min/max interval to actually set the “zoom level”?
I would have thought it would be the x range of the axis, i.e. if there is more than one month and less than twelve months of data shown then it would be this level;
Thanks @Skiks. You are setting dtick in the code, but isn’t the point of tickformatstops that the user can using the mouse cursor to set the “zoom level” to a given range?
So at first, when you’re looking at the full span of the whole time series, it makes sense for the range between x ticks to be wide. But as you zoom in, you want to see smaller (and more meaningful) x tick ranges. I.e;
Yes you are right, dtick and tickformatstops are not meant to work together, it was only for demonstration purpose
tickformatstops probably works with tickmode='auto', the range between 2 ticks is calculated automatically.
As you zoom, this range will change automatically if needed, and when you see it change, it can be in a different dtickrange you defined in tickformatstops and thus adapt the tick label format by the value corresponding to this dtickrange.
The range between 2 ticks switch automatically to 1 month, this time we are in dtickrange=[604800000, "M1"], (seem to be left side of range excluded and right side included), thus the tick label format “%e. %b w” still applies like “1. Mar w”
Thanks again @Skiks, I really appreciate your help.
Tbh, your answer has just raised more questions for me!
-Why did it go from tick spaces being ‘M3’ to ‘M2’? - who said anything about ‘M2’ spacing?
-When it is ‘M2’ why is it Mar, May, Jul etc rather than Apr, Jun, Aug etc
-When you zoomed from ‘M2’ to ‘M1’, what was it that prompted plotly just choose the next dtickrange? Was it because it is trying to fit 7-9 full tick spaces?
Actually, the last question is what I’m trying to understand/control.
^This is what I’m trying to control.
How do I tell plotly that at a given zoom level (i.e. x range), I want tick spacing to be XYZ, with formatting ABC and (as a bonus, what the first tick should be; i.e. start of the calendar quarter, or calendar month, or ISO week or whatever)
It’s plotly the boss
When you don’t set specific constrains (like dtick=“M1”), plotly is programmed to make a nice looking axis.
It kind of set for you tick0 the starting position and dtick the range between two ticks.
You can constrain a little the automatic mode by setting nticks the max number of ticks, plotly will still set the starting position and the tick range, but will manage to have as many ticks as possible to be close to nticks
No it is exactly because of the ranges dtickrange defined in tickformatstops.
But ‘M1’ is not obvious as is, as it is a boundary of 2 ranges [604800000, "M1"] and ["M1", "M12"],
as I stated above
by looking on the result on the displayed plot, meaning ‘M1’ seems to be considered in range [604800000, "M1"]
Like suggested in your other post, I think the solution is to use Dash and Graph prop relayoutData as input of a callback, which is triggered with zoom/pan.