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

Skip to content

Commit 0223174

Browse files
committed
Merge pull request #5764 from efiring/clabel_fontsize
BUG: make clabel obey fontsize kwarg
1 parent 772390f commit 0223174

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

lib/matplotlib/contour.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -182,19 +182,9 @@ def clabel(self, *args, **kwargs):
182182
self.labelIndiceList = indices
183183

184184
self.labelFontProps = font_manager.FontProperties()
185-
if fontsize is None:
186-
font_size = int(self.labelFontProps.get_size_in_points())
187-
else:
188-
if type(fontsize) not in [int, float, str]:
189-
raise TypeError("Font size must be an integer number.")
190-
# Can't it be floating point, as indicated in line above?
191-
else:
192-
if type(fontsize) == str:
193-
font_size = int(self.labelFontProps.get_size_in_points())
194-
else:
195-
self.labelFontProps.set_size(fontsize)
196-
font_size = fontsize
197-
self.labelFontSizeList = [font_size] * len(levels)
185+
self.labelFontProps.set_size(fontsize)
186+
font_size_pts = self.labelFontProps.get_size_in_points()
187+
self.labelFontSizeList = [font_size_pts] * len(levels)
198188

199189
if _colors is None:
200190
self.labelMappable = self

lib/matplotlib/tests/test_contour.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,19 @@ def test_contour_manual_labels():
166166
plt.clabel(cs, manual=pts)
167167

168168

169+
@image_comparison(baseline_images=['contour_labels_size_color'],
170+
extensions=['png'], remove_text=True)
171+
def test_contour_manual_labels():
172+
173+
x, y = np.meshgrid(np.arange(0, 10), np.arange(0, 10))
174+
z = np.max(np.dstack([abs(x), abs(y)]), 2)
175+
176+
plt.figure(figsize=(6, 2))
177+
cs = plt.contour(x, y, z)
178+
pts = np.array([(1.5, 3.0), (1.5, 4.4), (1.5, 6.0)])
179+
plt.clabel(cs, manual=pts, fontsize='small', colors=('r', 'g'))
180+
181+
169182
@image_comparison(baseline_images=['contour_manual_colors_and_levels'],
170183
extensions=['png'], remove_text=True)
171184
def test_given_colors_levels_and_extends():

0 commit comments

Comments
 (0)