-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[ENH]: Good looking date/time axes with primary and secondary annotation and interval annotation #27394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Does |
No, The examples with the true primary and secondary axes in the Generic Mapping Tools documentation on the other hand, convey a much more conventional calendar-like approach to displaying dates and times, that should be clear to readers of the plots much more quickly. Perhaps the functionality of Another example implementation of these two features, with an automatic selection of the appropriate ticks and labels, is available in a web application I have built: https://spaceweather.knmi.nl/viewer/. Here, the interval annotation feature was achieved by simply adding an offset to the labels, relative to the ticks, and changing their alignment (from centred to left-aligned). Having a choice to center those interval annotation labels between two ticks would be even better. |
We do not currently have a way to add an extra level of ticks. You can fake this with a secondary x axis or with minor and major ticks on the main axis. If I were doing it, I'd place a secondary xaxis at y=0 and just add carriage returns to the tick labels rather than messing with offsets by hand. Labelling time in general is quite hard and there will always be taste differences. If your taste differs from the available defaults, you are going to have to do some work. The general request for multiple label levels is the same as #6321 |
Thanks for those considerations. The Stack Overflow example mentioned in #6321, already implements both dual labels and interval labelling with some additional code. I agree that labelling time is hard, and the above would take a considerable implementation and fine-tuning effort. But I don't think the main differences between the examples under the links I gave above on the one hand, and those in date_concise_formatter.html and the current matplotlib default on the other, come down purely to a matter of taste. I think the readability/usability differences can be considered objectively. |
Edit 2: If I follow correctly, the simplest version of what's being proposed here is
Which I think is reasonable to implement at the major/minor axes - so no leveling - as a first pass. Then, building around some of the ideas here, what about something that can compose the various Datetime Locators/Formatters <- which side note, this was really hard to find & I wonder if making it easier to find would improve things. Something like this super explicit version as a first pass and then we can think about sensible defaults: DateCompositeLocator([WeekdayLocator(**params), MicrosecondLocator(params)] , separate_axes = False)
DateCompositeFormatter(list of format strings matching composite locator) Because here we know the hierarchy/it's defined by virtue of the units. The # of possible levels are fixed and we can start w/ no defaults and then grow out to defaults. This could also be a good starting point on which to build a more generalized solution later? |
Yes, something like that would be a very good starting point. The default locators/formatters for https://spaceweather.knmi.nl/viewer/ are implemented (in JS) here: https://gitlab.com/KNMI-OSS/spaceweather/knmi-hapi-timeline-viewer/-/blob/main/src/lib/svg_plots/plot_frame_components/datetimetickinfo.js |
The aesthetics of the date locators and formatters is a side issue to me - anyone can write their own to override the Matplotlib-offered ones, and the defaults aren't going to change until we do a style-break release. The first job is deciding on an API for how to add a second (or more) level of tick annotations.
I think the form of the API would need to be figured out first. For instance, I'm not a fan of the Locator controlling if there are two axis levels or not. The locator is really just there to give tick values. Rather it seems an Overall, the problem of adding a second level of tick labels is largely an issue of how to place the tick labels in a way that looks good without manual tweaking. It's a tricky problem in general. There will also be the question of styling how the intervals in the second row are indicated.
I'm sure it is possible to come up with metrics for such things, and design studies to measure them. |
Problem
The default matplotlib date/time axes are difficult to customize to look professional. Date values usually denote time intervals (days, months, years), but matplotlib default date labels are attached to single ticks that mark the start of that interval. And since all date/time annotations are usually put on a single axis, the labels get long, and often have to be plotted at an angle, which does not look pleasing and makes the plots more difficult to read.
Proposed solution
Good-looking and easy to read date/time axes need implementation of two features:
Some excellent examples of the look that can be achieved using these two features can be seen in the cookbook of the Generic Mapping Tools: https://docs.generic-mapping-tools.org/latest/cookbook/options.html#cartesian-time-axes
The "interval labels" feature could also be made reusable for custom interval annotations, like in the further example on that website: https://docs.generic-mapping-tools.org/latest/cookbook/options.html#custom-axes
The text was updated successfully, but these errors were encountered: