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
Passing clim as keyword argument to pcolormesh does not change limits. #10346
Not sure if this is really a bug or just a user issue. I expected that passing a clim tuple to pcolormesh with no vmin or vmax specified would update the color scale limits. I found that I had to use vmin and vmax instead. Maybe I am misunderstanding and vmin and vmax should always be used. However, it looks like the kwargs are passed into the QuadMesh constructor and then clim is overwritten with vmin and vmax, even in they are None and clim is given. (https://github.com/heath730/matplotlib/blob/master/lib/matplotlib/axes/_axes.py#L5629).
@jklymak They don't list clim as an arg for pcolormesh, but they say the properties of the QuadMesh object that pcolormesh creates can be controlled using kwargs (including clim). However, if you do pass clim it will get overwritten with vmin/vmax. I guess just using vmin/vmax is probably the simplest way to go though, I did come from a matlab background originally so I guess that's why I was trying to use clim instead of vmin/vmax in the first place.
Yep you are right. Thats actually pretty annoying. Not sure what should change. It should be possible to not override clim if vmin and vmax are not provided. But ideally both forms would not exist. I'm not sure what the history is here.
This is long-ago cleverness coming back to bite us. The clim kwarg is being inherited based on the ScalarMappable.set_clim method, via the call to Artist.update in the Collection.__init__. That's why we have all these horrendous tables clogging the documentation: mostly irrelevant "properties", also advertised as "kwargs" and inherited via this circuitous process.
Do you think a note in the docstring that the clim property of the returned QuadMesh will be replaced by vmin/vmax would be appropriate or is it better to leave as is? If I understand your explanation correctly, pcolormesh is not really meant to support clim, but that table is being pulled into the docs because of the class hierarchy.
The docstring is autogenerated from pieces pulled from various places, and used in many places. Maybe it would make sense to add a note to the set_clim docstring to the effect that it should not be used when vmin, vmax are available.
I suspect this clash between clim and vmin, vmax is widespread, and there are probably many other such inherited properties that it would be better not to expose as kwargs. I haven't thought it through, though.
fwiw I would just pass everything to QuadMesh and teach ScalarMappable how to handle them.
diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py
index df2ccd55e..77b9a8089 100644
--- a/lib/matplotlib/axes/_axes.py
+++ b/lib/matplotlib/axes/_axes.py
@@ -5866,11 +5866,6 @@ linewidth=2, markersize=12)
if not self._hold:
self.cla()
- alpha = kwargs.pop('alpha', None)
- norm = kwargs.pop('norm', None)
- cmap = kwargs.pop('cmap', None)
- vmin = kwargs.pop('vmin', None)
- vmax = kwargs.pop('vmax', None)
shading = kwargs.pop('shading', 'flat').lower()
antialiased = kwargs.pop('antialiased', False)
kwargs.setdefault('edgecolors', 'None')
@@ -5892,14 +5887,7 @@ linewidth=2, markersize=12)
collection = mcoll.QuadMesh(Nx - 1, Ny - 1, coords,
antialiased=antialiased, shading=shading,
**kwargs)
- collection.set_alpha(alpha)
collection.set_array(C)
- if norm is not None and not isinstance(norm, mcolors.Normalize):
- raise ValueError(
- "'norm' must be an instance of 'mcolors.Normalize'")
- collection.set_cmap(cmap)
- collection.set_norm(norm)
- collection.set_clim(vmin, vmax)
collection.autoscale_None()
self.grid(False)
diff --git a/lib/matplotlib/cm.py b/lib/matplotlib/cm.py
index ecd1179f1..c6cc87472 100644
--- a/lib/matplotlib/cm.py
+++ b/lib/matplotlib/cm.py
@@ -318,6 +318,12 @@ class ScalarMappable(object):
self.norm.vmax = vmax
self.changed()
+ def set_vmin(self, vmin):
+ self.set_clim(vmin=vmin)
+
+ def set_vmax(self, vmax):
+ self.set_clim(vmax=vmax)
+
def set_cmap(self, cmap):
"""
set the colormap for luminance data
or, if we decide that's not the route we want to take, we should just deprecate clim, instead of keeping it half-assed...
Note that the above solution will apply kwargs in the order they are given, so 1) that only works on Py3.6+ which keeps kwargs order (by mpl3 is coming :)) and 2) requires the user to pass the norm before the clims, which does not seem unreasonable...
You can do that. But you need to decide what takes precedence - vmin/vmax or clim. That’s pretty bad API if there are two ways to do the same thing with arbitrary precedence. I’d prefer to deprecate clim.
Reopening because the documentation change is fine but not really the root of the problem.
Activity
jklymak commentedon Jan 30, 2018
Do the docs say that you can pass
clim? I couldn't find anywhere that they say you can. There is apyplot.climbut thats a matlab-ism...I think having a
climargument andvmin/vmaxis asking for trouble...heathhenley commentedon Jan 31, 2018
@jklymak They don't list
climas an arg forpcolormesh, but they say the properties of theQuadMeshobject thatpcolormeshcreates can be controlled using kwargs (including clim). However, if you do passclimit will get overwritten withvmin/vmax. I guess just usingvmin/vmaxis probably the simplest way to go though, I did come from a matlab background originally so I guess that's why I was trying to usecliminstead ofvmin/vmaxin the first place.The docs I'm referring to are: https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.pcolormesh.html
jklymak commentedon Jan 31, 2018
Yep you are right. Thats actually pretty annoying. Not sure what should change. It should be possible to not override
climifvminandvmaxare not provided. But ideally both forms would not exist. I'm not sure what the history is here.efiring commentedon Jan 31, 2018
This is long-ago cleverness coming back to bite us. The clim kwarg is being inherited based on the
ScalarMappable.set_climmethod, via the call toArtist.updatein theCollection.__init__. That's why we have all these horrendous tables clogging the documentation: mostly irrelevant "properties", also advertised as "kwargs" and inherited via this circuitous process.heathhenley commentedon Jan 31, 2018
Do you think a note in the docstring that the
climproperty of the returnedQuadMeshwill be replaced by vmin/vmax would be appropriate or is it better to leave as is? If I understand your explanation correctly,pcolormeshis not really meant to supportclim, but that table is being pulled into the docs because of the class hierarchy.efiring commentedon Jan 31, 2018
The docstring is autogenerated from pieces pulled from various places, and used in many places. Maybe it would make sense to add a note to the set_clim docstring to the effect that it should not be used when vmin, vmax are available.
I suspect this clash between clim and vmin, vmax is widespread, and there are probably many other such inherited properties that it would be better not to expose as kwargs. I haven't thought it through, though.
anntzer commentedon Jan 31, 2018
fwiw I would just pass everything to QuadMesh and teach ScalarMappable how to handle them.
or, if we decide that's not the route we want to take, we should just deprecate clim, instead of keeping it half-assed...
Note that the above solution will apply kwargs in the order they are given, so 1) that only works on Py3.6+ which keeps kwargs order (by mpl3 is coming :)) and 2) requires the user to pass the norm before the clims, which does not seem unreasonable...
We also have a precedent of just forcing the order of the kwargs to something logically consistent in https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/text.py#L178.
jklymak commentedon Jan 31, 2018
You can do that. But you need to decide what takes precedence - vmin/vmax or clim. That’s pretty bad API if there are two ways to do the same thing with arbitrary precedence. I’d prefer to deprecate clim.
Reopening because the documentation change is fine but not really the root of the problem.
anntzer commentedon Nov 2, 2021
I think this was effectively fixed by #21146. Feel free to reopen if not.