Skip to content

ENH ticks sublabel display is now an option #7438

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 15 commits into from
Dec 1, 2016
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
14 changes: 12 additions & 2 deletions lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,10 @@ def __init__(self, ax, cmap=None,
self.locator = ticks # Handle default in _ticker()
if format is None:
if isinstance(self.norm, colors.LogNorm):
self.formatter = ticker.LogFormatterMathtext()
self.formatter = ticker.LogFormatterSciNotation()
elif isinstance(self.norm, colors.SymLogNorm):
self.formatter = ticker.LogFormatterSciNotation(
linthresh=self.norm.linthresh)
else:
self.formatter = ticker.ScalarFormatter()
elif cbook.is_string_like(format):
Expand Down Expand Up @@ -574,7 +577,14 @@ def _ticker(self):
b = self.norm.boundaries
locator = ticker.FixedLocator(b, nbins=10)
elif isinstance(self.norm, colors.LogNorm):
locator = ticker.LogLocator()
locator = ticker.LogLocator(subs='all')
elif isinstance(self.norm, colors.SymLogNorm):
# The subs setting here should be replaced
# by logic in the locator.
locator = ticker.SymmetricalLogLocator(
subs=np.arange(1, 10),
linthresh=self.norm.linthresh,
base=10)
else:
if mpl.rcParams['_internal.classic_mode']:
locator = ticker.MaxNLocator()
Expand Down
4 changes: 3 additions & 1 deletion lib/matplotlib/scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ def set_default_locators_and_formatters(self, axis):
axis.set_major_locator(LogLocator(self.base))
axis.set_major_formatter(LogFormatterSciNotation(self.base))
axis.set_minor_locator(LogLocator(self.base, self.subs))
axis.set_minor_formatter(LogFormatterSciNotation(self.base, self.subs))
axis.set_minor_formatter(
LogFormatterSciNotation(self.base,
labelOnlyBase=self.subs))

def get_transform(self):
"""
Expand Down
5 changes: 5 additions & 0 deletions lib/matplotlib/tests/test_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ def test_log_scatter():

buf = io.BytesIO()
fig.savefig(buf, format='svg')


if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
13 changes: 8 additions & 5 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ def test_SymmetricalLogLocator_set_params():
See if change was successful.
Should not exception.
"""
# since we only test for the params change. I will pass empty transform
sym = mticker.SymmetricalLogLocator(None)
sym = mticker.SymmetricalLogLocator(base=10, linthresh=1)
sym.set_params(subs=[2.0], numticks=8)
nose.tools.assert_equal(sym._subs, [2.0])
nose.tools.assert_equal(sym.numticks, 8)
Expand Down Expand Up @@ -240,7 +239,7 @@ def test_LogFormatter_sublabel():
ax.xaxis.set_major_locator(mticker.LogLocator(base=10, subs=[]))
ax.xaxis.set_minor_locator(mticker.LogLocator(base=10,
subs=np.arange(2, 10)))
ax.xaxis.set_major_formatter(mticker.LogFormatter())
ax.xaxis.set_major_formatter(mticker.LogFormatter(labelOnlyBase=True))
ax.xaxis.set_minor_formatter(mticker.LogFormatter(labelOnlyBase=False))
# axis range above 3 decades, only bases are labeled
ax.set_xlim(1, 1e4)
Expand All @@ -261,9 +260,13 @@ def test_LogFormatter_sublabel():
ax.set_xlim(1, 80)
_sub_labels(ax.xaxis, subs=[])

# axis range at 0 to 1 decades, label subs 2, 3, 6
# axis range at 0.4 to 1 decades, label subs 2, 3, 4, 6
ax.set_xlim(1, 8)
_sub_labels(ax.xaxis, subs=[2, 3, 6])
_sub_labels(ax.xaxis, subs=[2, 3, 4, 6])

# axis range at 0 to 0.4 decades, label all
ax.set_xlim(0.5, 0.9)
_sub_labels(ax.xaxis, subs=np.arange(2, 10, dtype=int))


def _logfe_helper(formatter, base, locs, i, expected_result):
Expand Down
Loading