| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
import numpy as np
import matplotlib.pyplot as plt
#from matplotlib.backend_bases import MouseButton
def pick_fn(mouseevent):
if mouseevent.inaxes is colorbar.ax:
print('pick\n\nPICKKKKKKK')
print(mouseevent.ydata, mouseevent.button)
def motion_fn(mouseevent):
if mouseevent.inaxes is colorbar.ax:
print(mouseevent.ydata, mouseevent.button)
pass
fig, ax = plt.subplots()
canvas = fig.canvas
arr = np.random.randn(100, 100)
axesimage = plt.imshow(arr)
colorbar = plt.colorbar(axesimage, ax=ax, use_gridspec=True)
# helps you see what value you are about to set the range to
colorbar.ax.set_navigate(True)
canvas.mpl_connect("motion_notify_event", motion_fn)
colorbar.ax.set_picker(True)
canvas.mpl_connect("button_press_event", pick_fn)
plt.show()works fine on this PR. |
Sorry, something went wrong.
| patch_trf = patch.get_transform() | ||
| updatex, updatey = patch_trf.contains_branch_seperately(self.transData) | ||
| if not (updatex or updatey): | ||
| return |
There was a problem hiding this comment.
Calling the transform below blows up needlessly because it is called, and then does nothing....
Sorry, something went wrong.
|
... interesting wrinkle. If an axes has an _axes_locator that is not None, tight_layout decides it can't handle it. Here the locator only is supposed to modify things in the direction perpendicular to the one tight_layout needs to worry about, so presumably it should be fine, but the warning still persists and breaks the docs build. |
Sorry, something went wrong.
|
I have to say, this was actually fewer image changes than I was expecting :) |
Sorry, something went wrong.
| np.testing.assert_allclose(cb.ax.get_position().extents, | ||
| [0.78375, 0.536364, 0.796147, 0.9], rtol=2e-3) | ||
|
|
||
|
|
There was a problem hiding this comment.
Surely this test was there for a reason, especially saying it was a "funny" error. Makes it seem like this should be investigated and updated rather than removed.
Sorry, something went wrong.
There was a problem hiding this comment.
This was testing the extend length being correct (its my test). We could go ahead and keep testing this, but it'd properly require an image test.
Sorry, something went wrong.
| except TypeError: | ||
| pass | ||
| lim = self._cbar._long_axis().get_view_interval() | ||
| self._cbar._short_axis().set_view_interval(*lim) |
There was a problem hiding this comment.
Do you also want to update the data interval of the short axis here?
Sorry, something went wrong.
There was a problem hiding this comment.
I'm not sure what you mean? We need to do this to make the aspect ratio of the colobar correct.
Sorry, something went wrong.
There was a problem hiding this comment.
OK, this has been removed. See comments
Sorry, something went wrong.
| if self._cbar.orientation == 'vertical': | ||
| if aspect: | ||
| ax.set_aspect(aspect*shrink) | ||
| offset = offset * pos.height |
There was a problem hiding this comment.
*= or even just explicitly put offset * pos.height into the translated call below.
Sorry, something went wrong.
|
|
||
| # make the inner axes smaller to make room for the extend rectangle | ||
| top = elower + inner_length | ||
| top = eupper + 1 |
There was a problem hiding this comment.
For consistency I'd suggest either defining bot = -elower here and using that below or using 1 + eupper in the calculations.
Sorry, something went wrong.
| self.ax.outer_ax.add_patch(patch) | ||
| antialiased=False, transform=self.ax.transAxes, | ||
| hatch=hatches[0], clip_on=False) | ||
| self.ax.add_patch(patch) |
There was a problem hiding this comment.
Because you're setting clip_on=False here, do you need to adjust the zorder of the patch at all so that it is behind the main axes?
Sorry, something went wrong.
There was a problem hiding this comment.
I think this is as it was before?
Sorry, something went wrong.
There was a problem hiding this comment.
This seems reasonable with the layer between the patch, the outline, and then the fill-ins for the extensions.
We do not keep a (named) reference to these patches, what do we do if we update the colormap?
Sorry, something went wrong.
| Colorbar(cax, cmap=cmap, norm=norm, | ||
| boundaries=boundaries, values=values, | ||
| extend=extension_type, extendfrac=extendfrac, | ||
| orientation='horizontal', spacing=spacing) |
There was a problem hiding this comment.
Dedent these also.
Sorry, something went wrong.
|
|
||
| def __call__(self, ax, renderer): | ||
|
|
||
| # make sure that lims and scales are the same |
There was a problem hiding this comment.
I'm not sure why this is necessary; I understand from some comments that this is due to aspect ratio handling?
Sorry, something went wrong.
There was a problem hiding this comment.
Right, the aspect of the axes is presently set via the usual ax.set_aspect, but that requires the limits and scales of the short and long axes to be the same.
However I'm starting to think that is a mistake, and we should perhaps just use something like set_box_aspect and get around all this awkwardness. Or just do it with the new colorbar axes locator.
Sorry, something went wrong.
There was a problem hiding this comment.
See comments, this has all be re-engineered.
Sorry, something went wrong.
|
latest commit changes the aspect ratio handling from a data-aspect ratio to a box aspect ratio. The "short" side of the colorbar now always has a linear scale and limits from 0-1, and only the "long" side gets a scale and variable data limits. This simplifies a lot of code.. Note I've added a colorbar.set_aspect and colorbar.set/get_scale. These will need whats-new entries (done) |
Sorry, something went wrong.
| cax.set_aspect(aspect, anchor=loc_settings["anchor"], adjustable='box') | ||
| cax.set_anchor(anchor) |
There was a problem hiding this comment.
Was loc_settings["anchor"] an error?
Sorry, something went wrong.
There was a problem hiding this comment.
Yeah, I assume that anchor was just ignored if passed as a kwarg. I'm not sure what happens if it is passed as a kwarg.
Sorry, something went wrong.
There was a problem hiding this comment.
Strange, it should just go through to set_anchor if it's not None.
Sorry, something went wrong.
There was a problem hiding this comment.
I think what is happening here is correct, and the old code was ignoring the user's specification of anchor, but maybe I'm not following...
Sorry, something went wrong.
|
Are the set_scale and set_aspect really necessary public functions on Colorbar and not just on the internal axis? set_aspect: This is generally on an Axes, so why not leave it on cbar.ax and let the new locator work on that? set_scale: I feel like this could cause confusion. The norm of the colorbar can be out of sync with the scale now? If I call cbar.set_scale('log')`, the ticks would be located in log-space, but the color normalization still done in linear space I believe. |
Sorry, something went wrong.
This is the same as colorbar(..., aspect=20), so it really is a colorbar method. The equivalent axes method is set_box_aspect, and indeed set_aspect will not work.
I needed to make this method, and didn't see that it needed to be private, but I don't feel strongly about it. Indeed it will only change the scale and not have anything to do with the norm's scale. |
Sorry, something went wrong.
|
Your new AxesLocator is the only thing calling cbar.set_aspect though because you just put it in. I'm suggesting that you can put these two calls up in the locator instead, without introducing new public API. (You added these two calls into ConstrainedLayout already, so I think the same idea could be applied in the Locator) self.ax.set_box_aspect(aspect)
self.ax.set_aspect('auto')
This seems like a real reason not to make this public. In your calls to self.set_scale(), you already have the long axis attribute above, so why not call self._long_axis().set_scale() there instead of introducing the new API? |
Sorry, something went wrong.
Absolutely. I'm just suggesting it may be more-generally useful as well to be able to set this after creating the colorbar, so why not expose it?
Yes, there is no reason for it to be public, other than user convenience. As I said, I don't feel super strongly about exposing this, but we have had requests to change the scale without changing the norm. For instance, it is not completely unreasonable to have a linear scale and a logarithmic norm. |
Sorry, something went wrong.
| cax.set_aspect(aspect, anchor=loc_settings["anchor"], adjustable='box') | ||
| cax.set_anchor(anchor) |
There was a problem hiding this comment.
Strange, it should just go through to set_anchor if it's not None.
Sorry, something went wrong.
|
I assume you'll fix the last thing. |
Sorry, something went wrong.
|
@QuLogic, sorry, what "last thing"? The anchor passthrough? I think the new code is correct... |
Sorry, something went wrong.
There was a problem hiding this comment.
Sorry, something went wrong.
#20501 (comment) longax wasn't removed. |
Sorry, something went wrong.
There was a problem hiding this comment.
Anyone can merge on CI green!
Sorry, something went wrong.
Previous overhaul packaged an inner and outer axes in a container "ColorbarAxes" and tried to dispatch methods between them. This overhaul takes the _much_ simpler approach of resizing the image using a custom _axes_locator that a) calls any existing locator b) or just uses the axes default position. The custom _axes_locator then shrinks the axes in the appropriate direction to make room for extend tri/rectangles. As with the previous fix, the extend tri/rectangles are drawn as patches in axes co-ordinates, rather than pcolormesh in "data" co-ordinates.
|
Thanks @QuLogic and @greglucas for all your help! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
PR Summary
OK, third time is the charm.
Previous overhaul packaged an inner and outer axes in a container "ColorbarAxes" and tried to dispatch methods between them.
This overhaul takes the much simpler approach of resizing the image using a custom _axes_locator that a) calls any existing locator b) or just uses the axes default position. The custom _axes_locator then shrinks the axes in the appropriate direction to make room for extend tri/rectangles. As with the previous fix, the extend tri/rectangles are drawn as patches in axes co-ordinates, rather than pcolormesh in "data" co-ordinates.
This addresses the concerns and closes #20479
PR Checklist