Skip to content

Colorbar with SymmetricalLogLocator now handles negative values (Pull request issue for #7202) #7211

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

Closed
wants to merge 2 commits into from
Closed
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
7 changes: 6 additions & 1 deletion lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,12 +600,17 @@ def _ticker(self):
formatter.set_data_interval(*intv)

b = np.array(locator())
if isinstance(locator, ticker.LogLocator):
if isinstance(locator, ticker.LogLocator) or isinstance(locator, ticker.SymmetricalLogLocator):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be simplified to:

 if isinstance(locator, (ticker.LogLocator, ticker.SymmetricalLogLocator)):

eps = 1e-10
b = b[(b <= intv[1] * (1 + eps)) & (b >= intv[0] * (1 - eps))]
else:
eps = (intv[1] - intv[0]) * 1e-10
b = b[(b <= intv[1] + eps) & (b >= intv[0] - eps)]

#failsafe in case less than 2 decades found
if len(b)<2:
b = np.array(locator())

self._tick_data_values = b
ticks = self._locate(b)
formatter.set_locs(b)
Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2126,6 +2126,8 @@ def get_log_range(lo, hi):
a_range = get_log_range(t, -vmin + 1)
else:
a_range = get_log_range(-vmax, -vmin + 1)
if vmin<0 and vmax<0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand this logic

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tacaswell
get_log_range will return a single decade for values bound by two consecutives 2**x:
for instance, -100<x<-10
hence, i'm artificially adding one decade more bounded to 0.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but why does this only apply to negative values?

a_range = ( a_range[0], a_range[1]+1 )
else:
a_range = (0, 0)

Expand Down