Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FIX colorbars for Norms that do not have a scale. #16392

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

Merged
merged 1 commit into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ def __init__(self, ax, cmap=None,
self.locator = None
self.formatter = None
self._manual_tick_data_values = None
self.__scale = None # linear, log10 for now. Hopefully more?

if ticklocation == 'auto':
ticklocation = 'bottom' if orientation == 'horizontal' else 'right'
Expand Down Expand Up @@ -585,8 +586,8 @@ def _use_auto_colorbar_locator(self):
one. (check is used twice so factored out here...)
"""
contouring = self.boundaries is not None and self.spacing == 'uniform'
return (type(self.norm) in [colors.Normalize, colors.LogNorm]
and not contouring)
return (type(self.norm) in [colors.Normalize, colors.LogNorm] and
not contouring)

def _reset_locator_formatter_scale(self):
"""
Expand All @@ -602,9 +603,14 @@ def _reset_locator_formatter_scale(self):
self.ax.set_xscale('log')
self.ax.set_yscale('log')
self.minorticks_on()
self.__scale = 'log'
else:
self.ax.set_xscale('linear')
self.ax.set_yscale('linear')
if type(self.norm) is colors.Normalize:
self.__scale = 'linear'
else:
self.__scale = 'manual'

def update_ticks(self):
"""
Expand Down Expand Up @@ -1119,13 +1125,13 @@ def _mesh(self):
else:
y = self._proportional_y()
xmid = np.array([0.5])
try:
if self.__scale != 'manual':
y = norm.inverse(y)
x = norm.inverse(x)
xmid = norm.inverse(xmid)
except ValueError:
# occurs for norms that don't have an inverse, in
# which case manually scale:
else:
# if a norm doesn't have a named scale, or
# we are not using a norm
dv = self.vmax - self.vmin
x = x * dv + self.vmin
y = y * dv + self.vmin
Expand Down
1 change: 0 additions & 1 deletion lib/matplotlib/tests/test_colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ def test_colorbar_get_ticks():
data = np.arange(1200).reshape(30, 40)
levels = [0, 200, 400, 600, 800, 1000, 1200]

plt.subplot()
plt.contourf(data, levels=levels)

# testing getter for user set ticks
Expand Down