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

Skip to content

Commit a1e9db1

Browse files
authored
Merge pull request #10129 from Raab70/bug-fix/logsymnorm-zero-labels
Fix multiple zero labels when using SymLogNorm
2 parents 2296775 + e9af134 commit a1e9db1

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/matplotlib/tests/test_colors.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,18 @@ def test_SymLogNorm_colorbar():
247247
plt.close(fig)
248248

249249

250+
def test_SymLogNorm_single_zero():
251+
"""
252+
Test SymLogNorm to ensure it is not adding sub-ticks to zero label
253+
"""
254+
fig = plt.figure()
255+
norm = mcolors.SymLogNorm(1e-5, vmin=-1, vmax=1)
256+
cbar = mcolorbar.ColorbarBase(fig.add_subplot(111), norm=norm)
257+
ticks = cbar.get_ticks()
258+
assert sum(ticks == 0) == 1
259+
plt.close(fig)
260+
261+
250262
def _inverse_tester(norm_instance, vals):
251263
"""
252264
Checks if the inverse of the given normalization is working.

lib/matplotlib/ticker.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2346,7 +2346,10 @@ def get_log_range(lo, hi):
23462346
if len(subs) > 1 or subs[0] != 1.0:
23472347
ticklocs = []
23482348
for decade in decades:
2349-
ticklocs.extend(subs * decade)
2349+
if decade == 0:
2350+
ticklocs.append(decade)
2351+
else:
2352+
ticklocs.extend(subs * decade)
23502353
else:
23512354
ticklocs = decades
23522355

0 commit comments

Comments
 (0)