-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
DOC: multilevel tick example #27411
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
DOC: multilevel tick example #27411
Conversation
e52f7d4
to
c39134b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done. I particularly like the progression from simple to complicated example, so the reader can see how it builds up.
My comments are all very picky, so please take or leave any of them.
# label the months: | ||
sec = ax.secondary_xaxis(location=-0.075) | ||
sec.xaxis.set_major_locator(mdates.MonthLocator(bymonthday=1)) | ||
sec.xaxis.set_major_formatter(mdates.DateFormatter(' %b')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume you add the spaces before the %b
to improve the alignment with the tick. I just spent longer than I care to admit trying to figure out a way to set the horizontal alignment of the labels, and now I think I understand why you want to overhaul Axis
!
For the record, this works, but I'm not sure it would be an improvement.
fig.draw_without_rendering() # Otherwise only one label exists to loop through. Is there a cheaper way to force tick generation?
for label in sec.xaxis.get_ticklabels():
label.set_horizontalalignment('left')
Is it worth a comment to explain the spaces though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's all pretty annoying. And of course that alignment only holds for ticks that presently exist - if you pan off to right or left the new ticks won't get the alignment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aI think lighter lift to improve this would be to add alignment to tick_params
#20644
# This example also differs from the above, in that we placed it at a | ||
# location below the main axes ``location=-0.075`` and then we hide the spine | ||
# by setting the line width to zero. That means that our formatter no longer | ||
# needs the carriage returns of the previous two examples. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a sentence near the top somewhere to explain why we do add the "\n" in those examples.
|
||
ax.plot(['cats', 'dogs', 'pigs', 'snakes', 'lizards', 'chickens', | ||
'eagles', 'herons', 'buzzards'], | ||
rng.normal(size=9)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rng.normal(size=9)) | |
rng.normal(size=9), 'o') |
I know it doesn't matter a jot for the purpose of the example, but lines between categorical data don't make sense to me.
sec.set_xticks([5, 15, 25], labels=['\nOughts', '\nTeens', '\nTwenties']) | ||
|
||
# %% | ||
# This example adds a second level of annotation to a categorical axis. Note |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# This example adds a second level of annotation to a categorical axis. Note | |
# The second example adds a second level of annotation to a categorical axis. Note |
To make it really obvious to the reader that we are moving on.
# This example adds a second level of annotation to a categorical axis. Note | ||
# that here we need to note that each animal (category) is assigned an integer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# This example adds a second level of annotation to a categorical axis. Note | |
# that here we need to note that each animal (category) is assigned an integer, | |
# This example adds a second level of annotation to a categorical axis. | |
# Here we need to note that each animal (category) is assigned an integer, |
Scans a little better for me.
|
||
# %% | ||
# Dates are another common place where we may want to have a second level of tick | ||
# labels. Here we take advantage of the ability to add an automatic locator and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# labels. Here we take advantage of the ability to add an automatic locator and | |
# labels. Next we take advantage of the ability to add an automatic locator and |
Moving on again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"In this last example,"
c39134b
to
8405388
Compare
doc/devel/index.rst
Outdated
`development version <https://matplotlib.org/devdocs/devel/index.html>`_ | ||
of this document as it will have the most up to date installation | ||
instructions, workflow process, and contributing guidelines. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where did this come from? I didn't see it before and it doesn't show in the "force-push" diff 😕
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've had that happen for this PR a couple of times where changes on main get shown as diffs in this PR? Not sure why, but a rebase on main fixes it
8405388
to
f962e7a
Compare
fix typo Co-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com>
@meeseeksdev backport to v3.8.x |
@meeseeksdev backport to v3.8.2-doc |
…411-on-v3.8.2-doc Backport PR #27411 on branch v3.8.2-doc (DOC: multilevel tick example)
…411-on-v3.8.x Backport PR #27411 on branch v3.8.x (DOC: multilevel tick example)
This adds an example showing one method of adding multilevel ticks to a plot.
Not a substitute for #6321, but shows that it's possible with minimal fussing. Also partially addresses #27394, or at least gives an example of how to achieve the date axis effect discussed there