You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
QuadMesh.get_clim changed behavior in 3.3.0rc1 #17703
Return the values (min, max) that are mapped to the colormap limits.
Without vmin or vmax arguments to pcolormesh, this returns the data minimal and maximal values. However in the presence of only one of vmin or vmax, a change occurred between 3.2.2 and 3.3.0rc1. In 3.3.0rc1 it returns the input vmin and vmax, though only one of them was specified. The provided examples also happens (with slight output changes) for setting vmax instead of vmin.
Ah, it looks like in some cases we either called set_clim() or called autoscale_none but in some cases we did both. #15769 standardized everything to always do or. The autoscaling will eventually get taken care of down stream during the draw process.
Adding mesh.autoscale_None() before checking the limits fixes the old behavior (without forcing a full draw).
I don't see a way to put a deprecation warning on this behavior without being too annoying so I think out options are
document this as a hard break with the work-around of calling autoscale_None if you need to get the clim before drawing
add back the special casing from pcolor and pcolormesh and accept the slight difference in behavior between the artists
change behavior of everything else and make _scale_norm always call autoscale_None (which is an API change everywhere else)
While writing this out I am various points had convinced my self that all 3 options were the "best" option ;)
1 / 3 get us consistency but break different directions on if we should resolve the "auto" limit as soon as possible or as late as possible
2 gets us a little change in behavior as possible, but means that the early/late resolution varies by plotting method / Aritst.
We discussed this on the call and noted that if you pass nothing we call autoscale_None at init time. I am going to write up a set of example to make sure we fully understand what it is going on, when various things are called.
pass no norm / vmin / vmax -> call autoscale_None on data passed in immediately
pass norm -> call autoscale_None on data passed in immediately
pass vmin or vmax -> defer calling autoscale_None until the norm actually need to be used
pass vmin and vmax -> doesn't matter because nothing to autoscale
I am more convinced that we want to change it so in all cases when the Axes methods return we have fully resolved the vmin/vmax based on the input of {norm, vmin, vmax, data}, but we will need to document this as an intentional API change. This is going to break people who
a) pass in dummy data + one of vmin or vmax
b) re-set the data in the artist before the first time the norm is used (via drawing, adding a colorbar, direct usage...)
I am hoping this is rare because it seems like it is quite brittle.
This is what I was using to play with this:
importfunctoolsimportmatplotlib.pyplotaspltimportmatplotlib.colorsasmcolorsimportnumpyasnpclassForgivingNorm(mcolors.Normalize):
@functools.wraps(mcolors.Normalize.__call__)def__call__(self, value, *args, **kwargs):
try:
returnsuper().__call__(value, *args, **kwargs)
exceptValueError:
ifself.vmin<self.vmax:
# not sure why we are here?!raise# we are now here because self.vmax < self.vmin# normally this is something we raise an exception and kill# the draw on, but we want this to work result, is_scalar=self.process_value(value)
result=np.ma.array(result.data, mask=True, copy=False)
ifis_scalar:
result=result[0]
returnresultdef__repr__(self):
returnf'<ForgivingNorm(vmin={self.vmin}, vmax={self.vmax})>'# monkey patch for reasonsmcolors.Normalize=ForgivingNormzero_data=np.zeros((5, 5))
ramp_data=np.arange(25).reshape(5, 5) +.5defrun_test(zero_data, ramp_data, *, early_autoscale_None, make_norm):
fig, ax_arr=plt.subplots(2, 2, squeeze=False)
[[ax1, ax2], [ax3, ax4]] =ax_arrim_dict= {}
forj, (ax, kwargs) inenumerate(
zip(ax_arr.ravel(), ({}, {"vmin": 10}, {"vmax": 15}, {"vmin": 10, "vmax": 15}))
):
ifmake_norm:
kwargs= {'norm': ForgivingNorm(**kwargs)}
im_dict[j] =im=ax.imshow(zero_data, **kwargs)
ifearly_autoscale_None:
im.autoscale_None()
a=f'pre: {im.get_clim()}'im.set_data(ramp_data)
# this will happen eventually during the rendering, do it here# to capture the resultim.autoscale_None()
b=f'post: {im.get_clim()}'ax.set_title(f"{kwargs=}\n{a}{b}")
fig.suptitle(f"{early_autoscale_None=}{make_norm=}")
returnfig, ax_arr, im_dict
Activity
jklymak commentedon Jun 22, 2020
I'm not sure if this behaviour is expected new behaviour or not. 0a2f082 is the commit (@timhoffm)
#15769
tacaswell commentedon Jun 22, 2020
Ah, it looks like in some cases we either called
set_clim()or calledautoscale_nonebut in some cases we did both. #15769 standardized everything to always door. The autoscaling will eventually get taken care of down stream during the draw process.Adding
mesh.autoscale_None()before checking the limits fixes the old behavior (without forcing a full draw).I don't see a way to put a deprecation warning on this behavior without being too annoying so I think out options are
autoscale_Noneif you need to get the clim before drawing_scale_normalways callautoscale_None(which is an API change everywhere else)While writing this out I am various points had convinced my self that all 3 options were the "best" option ;)
1 / 3 get us consistency but break different directions on if we should resolve the "auto" limit as soon as possible or as late as possible
2 gets us a little change in behavior as possible, but means that the early/late resolution varies by plotting method / Aritst.
tacaswell commentedon Jun 22, 2020
And thank you @MaozGelbart for testing the RC :)
tacaswell commentedon Jun 22, 2020
We discussed this on the call and noted that if you pass nothing we call
autoscale_Noneat init time. I am going to write up a set of example to make sure we fully understand what it is going on, when various things are called.tacaswell commentedon Jun 22, 2020
This turned into a rabbit hole of complexity.
This is the current state for everything on 3.3
I am more convinced that we want to change it so in all cases when the
Axesmethods return we have fully resolved the vmin/vmax based on the input of {norm, vmin, vmax, data}, but we will need to document this as an intentional API change. This is going to break people whoa) pass in dummy data + one of vmin or vmax
b) re-set the data in the artist before the first time the norm is used (via drawing, adding a colorbar, direct usage...)
I am hoping this is rare because it seems like it is quite brittle.
This is what I was using to play with this:
API: resolve unset vmin / vmax in all ScalarMapple based methods
API: resolve unset vmin / vmax in all ScalarMapple based methods
API: resolve unset vmin / vmax in all ScalarMapple based methods