-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix colorbar exponents #22313
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
Fix colorbar exponents #22313
Conversation
a97402c
to
5d38073
Compare
... note that horizontal colorbars don't suffer from this problem so nothing was changed for XAxis.... |
# Special case for colorbars: | ||
bbox = self.axes.spines['outline'].get_window_extent() | ||
else: | ||
bbox = self.axes.bbox |
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.
Would it make sense to update the axes.bbox
in Colorbar to be the full spines outline? Move it up a level, so everything is referencing the same full bbox rather than just the text here. I'm not sure if that would mess up the tickers to draw in the extends region or not then...
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.
ax.transAxes
comes from the ax.bbox
, so I don't think that would work as the axes extends are drawn in transAxes
. I appreciate what you are saying though, it is a bit of a hack to special-case colorbars here...
Another alternative is to turn the axis off, use ax.get_tightbbox()
and then turn the axis back on again. But I think get_tightbbox
can get pretty expensive depending on artists. This is quite fast...
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 try to paraphrase: the colorbar axes has additional decorations which are outside the bbox but need to be taken into accout for shifting the offset text? In that case, do we need a concept for "bbox with decorations"?
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.
We do, it's called get_tightbbox. However that is defined on the axes and takes into account the axis, and this exponent is part of the axis, so you get an infinite recursion. I guess we could change get_tightbbox to accept a list of artists to exclude, but I'm not convinced that is any better than this solution. And again get_tightbbox can be very expensive.
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.
Thanks for the explanation. I don't claim to I know how the correct or practical solution. I was just trying to understand what's going on.
... moved to draft. cb.ax.set_title has the sae problem (though that usage is more rare, I expect) |
07bf9b2
to
2fd7a26
Compare
1933d58
to
4c371d0
Compare
Power-cycled now that we have fixed CI |
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.
Doc failure appears relevant.
Yes it does look relevant. Are you trying to get 3.5.2 out the door? I'm away from my computer until next wed (16 feb). Looks like the check for outline in the colorbar spine dict is not correct. |
No, not yet, probably next week. |
I can fix the 17th or so, but not before. If anyone wants to push a check to the PR it's not a problem. Thanks! |
@@ -505,7 +505,7 @@ def my_plotter(ax, data1, data2, param_dict): | |||
|
|||
pc = axs[1, 1].scatter(data1, data2, c=data3, cmap='RdBu_r') | |||
fig.colorbar(pc, ax=axs[1, 1], extend='both') | |||
axs[1, 1].set_title('scatter()'); | |||
axs[1, 1].set_title('scatter()') |
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.
these semicolons dont' work anyways, so removed it here...
OK, I admit to being quite stymied by the doc failure. What is happening is that the quick_start code is somehow creating a second figure in the pyplot registry, and this second figure is not quite setup properly. You can check this by adding print statements to the The root of the problem seems to be the deepcopy in matplotlib/lib/matplotlib/colorbar.py Line 1161 in b80bc91
If I remove this, then the sphinx scraper doesn't create the extra figure. The Looking at the code here, it definitely somehow triggers this weirdness, but I'm not understanding why it should. The reproducer here is to put print statements in
make html
|
Strange indeed... This looks like it is also not working correctly on the current docs build on main, although not failing. So, I don't think this PR is a culprit, just hitting a louder failure. I'll try and dig deeper this evening if @anntzer doesn't figure it out before that. |
Ah, good catch. Yes, this PR is probably squeaking because the spine is squished to nothing in the weird second figure. Again, it has something to do with the deepcopy in colorbar. If I remove that it seems to work fine. But the deepcopy has been around for a while, so I suspect some of the recent changes to the norms. |
I probably won't have the time to investigate this for a few days, sorry. I'll try to get back to it later... |
A fix to remove the deepcopy is in #22523, which solves the docs build here, but does not solve the underlying problem that could crop up somewhere else. The root cause bisects to: #21597 |
FIX: title as well
522bc6d
to
707d8a2
Compare
Owee, I'm MrMeeseeks, Look at me. There seem to be a conflict, please backport manually. Here are approximate instructions:
And apply the correct labels and milestones. Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon! Remember to remove the If these instructions are inaccurate, feel free to suggest an improvement. |
@jklymak @greglucas Sorry I didn't have the time to look at this; I'm trying to catch up a bit now. If I understand correctly there may still be a bug wrt deepcopying norms made with make_norm_from_scale? (which #22523 works around, but may otherwise may still be present?) Do colorbars need to be involved at all? Do you have a repro I can look at? (other than reverting #22523, as that PR seems like a good idea to me regardless) |
Yes, they are still broken and you actually had a patch :) You can add this to the current test: I also was curious on whether this would be one of the cases where a metaclass might help as being a kind of class factory here, but I didn't think about that too much. |
…3.5.x Backport PR #22313 on branch v3.5.x (Fix colorbar exponents)
PR Summary
Fix offsetText for colorbars with extends so they are above the extends... Closes #22312
Before
After
PR Checklist
Tests and Styling
pytest
passes).flake8-docstrings
and runflake8 --docstring-convention=all
).Documentation
doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).