Skip to content

Fix multiple zero labels for SymLogNorm colorbar #10128

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
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
6 changes: 6 additions & 0 deletions doc/users/next_whats_new/2017-12-27_legend_title_size_rc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Legend Title Size rc parameter
------------------------------

A new rc parameter has been added as an option in your matplotlibrc allowing you to control the font size of the legend title.

`legend.titlesize = 'large'`
2 changes: 1 addition & 1 deletion lib/matplotlib/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ def __init__(self, parent, handles, labels,
self.get_frame().set_alpha(framealpha)

self._loc = loc
self.set_title(title)
self.set_title(title, prop={"size": rcParams["legend.titlesize"]})
self._last_fontsize_points = self._fontsize
self._draggable = None

Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,7 @@ def _validate_linestyle(ls):
# the number of points in the legend line for scatter
'legend.scatterpoints': [1, validate_int],
'legend.fontsize': ['medium', validate_fontsize],
'legend.titlesize': ['medium', validate_fontsize],
# the relative size of legend markers vs. original
'legend.markerscale': [1.0, validate_float],
'legend.shadow': [False, validate_bool],
Expand Down
11 changes: 11 additions & 0 deletions lib/matplotlib/tests/test_legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,17 @@ def test_rc():
title="My legend")


def test_rc_title_size():
test_legend_title_size = 18.0
mpl.rcParams['legend.titlesize'] = test_legend_title_size
plt.figure()
ax = plt.subplot(121)
ax.scatter(np.arange(10), np.arange(10, 0, -1), label='two')
leg = ax.legend(loc="center left", bbox_to_anchor=[1.0, 0.5],
title="My legend")
assert leg.get_title().get_fontsize() == test_legend_title_size


@image_comparison(baseline_images=['legend_expand'], remove_text=True)
def test_legend_expand():
'Test expand mode'
Expand Down
14 changes: 10 additions & 4 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,7 @@ class LogFormatterMathtext(LogFormatter):
"""
Format values for log axis using ``exponent = log_base(value)``.
"""
_min_zero_pos = None

def _non_decade_format(self, sign_string, base, fx, usetex):
'Return string for non-decade locations'
Expand All @@ -1076,16 +1077,21 @@ def __call__(self, x, pos=None):
"""
Return the format for tick value `x`.

The position `pos` is ignored.
The position `pos` is used for SymLogNorm for ensuring
only one zero entry is present.
"""
usetex = rcParams['text.usetex']
min_exp = rcParams['axes.formatter.min_exponent']

if x == 0: # Symlog
if usetex:
return '$0$'
if self._min_zero_pos is None:
self._min_zero_pos = pos
if usetex:
return '$0$'
else:
return '$%s$' % _mathdefault('0')
else:
return '$%s$' % _mathdefault('0')
return ''

sign_string = '-' if x < 0 else ''
x = abs(x)
Expand Down
1 change: 1 addition & 0 deletions matplotlibrc.template
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ backend : $TEMPLATE_BACKEND
#legend.scatterpoints : 1 # number of scatter points
#legend.markerscale : 1.0 # the relative size of legend markers vs. original
#legend.fontsize : medium
#legend.titlesize : medium # fontsize of the legend title
# Dimensions as fraction of fontsize:
#legend.borderpad : 0.4 # border whitespace
#legend.labelspacing : 0.5 # the vertical space between the legend entries
Expand Down