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

Skip to content

Commit fb4b061

Browse files
authored
Merge pull request #7438 from NelleV/7202_symlog_colorbar_
ENH: ticks sublabel display is now an option
2 parents 0b6898b + ecc6212 commit fb4b061

File tree

5 files changed

+227
-99
lines changed

5 files changed

+227
-99
lines changed

lib/matplotlib/colorbar.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,10 @@ def __init__(self, ax, cmap=None,
311311
self.locator = ticks # Handle default in _ticker()
312312
if format is None:
313313
if isinstance(self.norm, colors.LogNorm):
314-
self.formatter = ticker.LogFormatterMathtext()
314+
self.formatter = ticker.LogFormatterSciNotation()
315+
elif isinstance(self.norm, colors.SymLogNorm):
316+
self.formatter = ticker.LogFormatterSciNotation(
317+
linthresh=self.norm.linthresh)
315318
else:
316319
self.formatter = ticker.ScalarFormatter()
317320
elif cbook.is_string_like(format):
@@ -574,7 +577,14 @@ def _ticker(self):
574577
b = self.norm.boundaries
575578
locator = ticker.FixedLocator(b, nbins=10)
576579
elif isinstance(self.norm, colors.LogNorm):
577-
locator = ticker.LogLocator()
580+
locator = ticker.LogLocator(subs='all')
581+
elif isinstance(self.norm, colors.SymLogNorm):
582+
# The subs setting here should be replaced
583+
# by logic in the locator.
584+
locator = ticker.SymmetricalLogLocator(
585+
subs=np.arange(1, 10),
586+
linthresh=self.norm.linthresh,
587+
base=10)
578588
else:
579589
if mpl.rcParams['_internal.classic_mode']:
580590
locator = ticker.MaxNLocator()

lib/matplotlib/scale.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,9 @@ def set_default_locators_and_formatters(self, axis):
249249
axis.set_major_locator(LogLocator(self.base))
250250
axis.set_major_formatter(LogFormatterSciNotation(self.base))
251251
axis.set_minor_locator(LogLocator(self.base, self.subs))
252-
axis.set_minor_formatter(LogFormatterSciNotation(self.base, self.subs))
252+
axis.set_minor_formatter(
253+
LogFormatterSciNotation(self.base,
254+
labelOnlyBase=self.subs))
253255

254256
def get_transform(self):
255257
"""

lib/matplotlib/tests/test_scale.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,8 @@ def test_log_scatter():
4646

4747
buf = io.BytesIO()
4848
fig.savefig(buf, format='svg')
49+
50+
51+
if __name__ == '__main__':
52+
import nose
53+
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/tests/test_ticker.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ def test_SymmetricalLogLocator_set_params():
162162
See if change was successful.
163163
Should not exception.
164164
"""
165-
# since we only test for the params change. I will pass empty transform
166-
sym = mticker.SymmetricalLogLocator(None)
165+
sym = mticker.SymmetricalLogLocator(base=10, linthresh=1)
167166
sym.set_params(subs=[2.0], numticks=8)
168167
nose.tools.assert_equal(sym._subs, [2.0])
169168
nose.tools.assert_equal(sym.numticks, 8)
@@ -240,7 +239,7 @@ def test_LogFormatter_sublabel():
240239
ax.xaxis.set_major_locator(mticker.LogLocator(base=10, subs=[]))
241240
ax.xaxis.set_minor_locator(mticker.LogLocator(base=10,
242241
subs=np.arange(2, 10)))
243-
ax.xaxis.set_major_formatter(mticker.LogFormatter())
242+
ax.xaxis.set_major_formatter(mticker.LogFormatter(labelOnlyBase=True))
244243
ax.xaxis.set_minor_formatter(mticker.LogFormatter(labelOnlyBase=False))
245244
# axis range above 3 decades, only bases are labeled
246245
ax.set_xlim(1, 1e4)
@@ -261,9 +260,13 @@ def test_LogFormatter_sublabel():
261260
ax.set_xlim(1, 80)
262261
_sub_labels(ax.xaxis, subs=[])
263262

264-
# axis range at 0 to 1 decades, label subs 2, 3, 6
263+
# axis range at 0.4 to 1 decades, label subs 2, 3, 4, 6
265264
ax.set_xlim(1, 8)
266-
_sub_labels(ax.xaxis, subs=[2, 3, 6])
265+
_sub_labels(ax.xaxis, subs=[2, 3, 4, 6])
266+
267+
# axis range at 0 to 0.4 decades, label all
268+
ax.set_xlim(0.5, 0.9)
269+
_sub_labels(ax.xaxis, subs=np.arange(2, 10, dtype=int))
267270

268271

269272
def _logfe_helper(formatter, base, locs, i, expected_result):

0 commit comments

Comments
 (0)