Skip to content

Mask invalid values by default when setting log scale #8836

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 5 commits into from
Jul 15, 2017
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
8 changes: 8 additions & 0 deletions doc/api/api_changes/2017-07-03-DS-logscale_masked.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Default behavior of log scales changed to mask <= 0 values
``````````````````````````````````````````````````````````

Calling `matplotlib.axes.Axes.set_xscale` or `matplotlib.axes.Axes.set_yscale`
now uses 'mask' as the default method to handle invalid values (as opposed to
'clip'). This means that any values <= 0 on a log scale will not be shown.

Previously they were clipped to a very small number and shown.
6 changes: 4 additions & 2 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,6 @@ def semilogx(self, *args, **kwargs):
self.cla()
d = {'basex': kwargs.pop('basex', 10),
'subsx': kwargs.pop('subsx', None),
'nonposx': kwargs.pop('nonposx', 'mask'),
}

self.set_xscale('log', **d)
Expand Down Expand Up @@ -1629,7 +1628,6 @@ def semilogy(self, *args, **kwargs):
self.cla()
d = {'basey': kwargs.pop('basey', 10),
'subsy': kwargs.pop('subsy', None),
'nonposy': kwargs.pop('nonposy', 'mask'),
}
self.set_yscale('log', **d)
b = self._hold
Expand Down Expand Up @@ -2753,6 +2751,10 @@ def errorbar(self, x, y, yerr=None, xerr=None,

%(Line2D)s

Notes
-----
Error bars with negative values will not be shown when plotted on a
logarithmic axis.
"""
kwargs = cbook.normalize_kwargs(kwargs, _alias_map)
# anything that comes in as 'None', drop so the default thing
Expand Down
8 changes: 4 additions & 4 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2961,10 +2961,10 @@ def set_xscale(self, value, **kwargs):

matplotlib.scale.LogisticTransform : logit transform
"""
# If the scale is being set to log, clip nonposx to prevent headaches
# If the scale is being set to log, mask nonposx to prevent headaches
# around zero
if value.lower() == 'log' and 'nonposx' not in kwargs:
kwargs['nonposx'] = 'clip'
kwargs['nonposx'] = 'mask'

g = self.get_shared_x_axes()
for ax in g.get_siblings(self):
Expand Down Expand Up @@ -3255,10 +3255,10 @@ def set_yscale(self, value, **kwargs):

matplotlib.scale.LogisticTransform : logit transform
"""
# If the scale is being set to log, clip nonposy to prevent headaches
# If the scale is being set to log, mask nonposy to prevent headaches
# around zero
if value.lower() == 'log' and 'nonposy' not in kwargs:
kwargs['nonposy'] = 'clip'
kwargs['nonposy'] = 'mask'

g = self.get_shared_y_axes()
for ax in g.get_siblings(self):
Expand Down
Binary file modified lib/matplotlib/tests/baseline_images/test_axes/log_scales.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading