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

Skip to content

Commit cede71d

Browse files
committed
FIX: correctly process the tick label size
Passing the size positional caused it to be treated as a fontconfig pattern. For the relative sizes without '-' in them this formally works and stashes the relative size in the family. We don't actually resolve that we can _find_ the font so this, while wrong, is not noticed and when we ask for the size it gives us back the default size so our size estimate was silently wrong. In the cases where we have a '-' in the relative size the fontconfig pattern parsing fails when we try to estimate the size. closes #17670
1 parent faffaa1 commit cede71d

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

lib/matplotlib/axis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ def _get_tick_label_size(self, axis_name):
13401340
tick_kw = self._major_tick_kw
13411341
size = tick_kw.get('labelsize',
13421342
mpl.rcParams[f'{axis_name}tick.labelsize'])
1343-
return mtext.FontProperties(size).get_size_in_points()
1343+
return mtext.FontProperties(size=size).get_size_in_points()
13441344

13451345
def _copy_tick_props(self, src, dest):
13461346
"""Copy the properties from *src* tick to *dest* tick."""

lib/matplotlib/tests/test_axes.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
import matplotlib as mpl
2222
from matplotlib.testing.decorators import (
2323
image_comparison, check_figures_equal, remove_ticks_and_titles)
24-
import matplotlib.pyplot as plt
25-
import matplotlib.markers as mmarkers
26-
import matplotlib.patches as mpatches
2724
import matplotlib.colors as mcolors
2825
import matplotlib.dates as mdates
26+
import matplotlib.font_manager as mfont_manager
27+
import matplotlib.markers as mmarkers
28+
import matplotlib.patches as mpatches
29+
import matplotlib.pyplot as plt
2930
import matplotlib.ticker as mticker
3031
import matplotlib.transforms as mtransforms
3132
from numpy.testing import (
@@ -6322,3 +6323,17 @@ def test_autoscale_tiny_sticky():
63226323
ax.bar(0, 1e-9)
63236324
fig.canvas.draw()
63246325
assert ax.get_ylim() == (0, 1.05e-9)
6326+
6327+
6328+
@pytest.mark.parametrize('size', [size for size in mfont_manager.font_scalings
6329+
if size is not None])
6330+
@pytest.mark.style('default')
6331+
def test_relative_ticklabel_sizes(size):
6332+
matplotlib.rcParams['xtick.labelsize'] = size
6333+
matplotlib.rcParams['ytick.labelsize'] = size
6334+
fig, ax = plt.subplots()
6335+
fig.canvas.draw()
6336+
6337+
for name, axis in zip(['x', 'y'], [ax.xaxis, ax.yaxis]):
6338+
for tick in axis.get_major_ticks():
6339+
assert tick.label1.get_size() == axis._get_tick_label_size(name)

0 commit comments

Comments
 (0)