From add6ac2d21b559a251aca3b320333776337390e7 Mon Sep 17 00:00:00 2001 From: ain-soph Date: Wed, 28 Apr 2021 16:26:38 -0400 Subject: [PATCH 01/16] fix mathtext.fontset issue --- lib/matplotlib/font_manager.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/matplotlib/font_manager.py b/lib/matplotlib/font_manager.py index a5fdc32b268b..05c3844bc5ef 100644 --- a/lib/matplotlib/font_manager.py +++ b/lib/matplotlib/font_manager.py @@ -656,6 +656,7 @@ def __init__(self, if (style is None and variant is None and weight is None and stretch is None and size is None and fname is None): self.set_fontconfig_pattern(family) + self.set_math_fontfamily(math_fontfamily) return self.set_family(family) From af1ce2f0c577dcfb26a0fdb570d9044b1c42e565 Mon Sep 17 00:00:00 2001 From: ain-soph Date: Wed, 28 Apr 2021 17:10:44 -0400 Subject: [PATCH 02/16] fix argument order issue --- lib/matplotlib/text.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 072a07f503d3..34e2b75f0bfa 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -176,9 +176,10 @@ def update(self, kwargs): kwargs = dict(kwargs) sentinel = object() # bbox can be None, so use another sentinel. # Update fontproperties first, as it has lowest priority. - fontproperties = kwargs.pop("fontproperties", sentinel) - if fontproperties is not sentinel: - self.set_fontproperties(fontproperties) + for alias in ["fontproperties", "font", "font_properties"]: + fontproperties = kwargs.pop(alias, sentinel) + if fontproperties is not sentinel: + self.set_fontproperties(fontproperties) # Update bbox last, as it depends on font properties. bbox = kwargs.pop("bbox", sentinel) super().update(kwargs) From ca4b5af056a749f0f792f41799888f7ebd6bfd2e Mon Sep 17 00:00:00 2001 From: ain-soph Date: Wed, 28 Apr 2021 17:27:33 -0400 Subject: [PATCH 03/16] better fix using alias_map --- lib/matplotlib/text.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 34e2b75f0bfa..265cc2c88e53 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -176,7 +176,8 @@ def update(self, kwargs): kwargs = dict(kwargs) sentinel = object() # bbox can be None, so use another sentinel. # Update fontproperties first, as it has lowest priority. - for alias in ["fontproperties", "font", "font_properties"]: + alias_map=["fontproperties"]+self._alias_map["fontproperties"] + for alias in alias_map: fontproperties = kwargs.pop(alias, sentinel) if fontproperties is not sentinel: self.set_fontproperties(fontproperties) From ca241dd5a553490ad95a6bdf3aa5489f37539541 Mon Sep 17 00:00:00 2001 From: ain-soph Date: Wed, 28 Apr 2021 17:29:03 -0400 Subject: [PATCH 04/16] indent fix --- lib/matplotlib/text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 265cc2c88e53..07528640abc4 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -176,7 +176,7 @@ def update(self, kwargs): kwargs = dict(kwargs) sentinel = object() # bbox can be None, so use another sentinel. # Update fontproperties first, as it has lowest priority. - alias_map=["fontproperties"]+self._alias_map["fontproperties"] + alias_map=["fontproperties"] + self._alias_map["fontproperties"] for alias in alias_map: fontproperties = kwargs.pop(alias, sentinel) if fontproperties is not sentinel: From 87c80b63706e2768ad19d7d5115c2a139f87de3a Mon Sep 17 00:00:00 2001 From: Ren Pang Date: Wed, 28 Apr 2021 19:41:19 -0400 Subject: [PATCH 05/16] Update lib/matplotlib/text.py indent fix Co-authored-by: Elliott Sales de Andrade --- lib/matplotlib/text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 07528640abc4..c99fd5631a2d 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -176,7 +176,7 @@ def update(self, kwargs): kwargs = dict(kwargs) sentinel = object() # bbox can be None, so use another sentinel. # Update fontproperties first, as it has lowest priority. - alias_map=["fontproperties"] + self._alias_map["fontproperties"] + alias_map = ["fontproperties", *self._alias_map["fontproperties"]] for alias in alias_map: fontproperties = kwargs.pop(alias, sentinel) if fontproperties is not sentinel: From 0e9954c1b3a13be4c44026261fb124617ed3a166 Mon Sep 17 00:00:00 2001 From: ain-soph Date: Wed, 28 Apr 2021 20:28:38 -0400 Subject: [PATCH 06/16] add test --- lib/matplotlib/tests/test_mathtext.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/matplotlib/tests/test_mathtext.py b/lib/matplotlib/tests/test_mathtext.py index 5236e1299809..60f7f71c1252 100644 --- a/lib/matplotlib/tests/test_mathtext.py +++ b/lib/matplotlib/tests/test_mathtext.py @@ -385,3 +385,30 @@ def test_math_fontfamily(): size=24, math_fontfamily='dejavusans') fig.text(0.2, 0.3, r"$This\ text\ should\ have\ another$", size=24, math_fontfamily='stix') + +def test_default_math_fontfamily(): + mpl.rcParams['mathtext.fontset'] = 'cm' + test_str = r'Foo: $\alpha_{i+1}^j = {\rm sin}(2\pi f_j t_i) e^{-5 t_i/\tau}$' + + buff = io.BytesIO() + fig, ax = plt.subplots() + + prop1 = fig.text(0.1, 0.1, test_str, font='Arial').get_fontproperties() + assert prop1.get_math_fontfamily() == 'cm' + + prop2 = fig.text(0.1, 0.2, test_str, fontproperties='Arial').get_fontproperties() + assert prop2.get_math_fontfamily() == 'cm' + + prop3 = fig.text(0.1, 0.3, test_str, math_fontfamily='dejavusans', font='Arial').get_fontproperties() + assert prop3.get_math_fontfamily() == 'dejavusans' + + prop4 = fig.text(0.1, 0.4, test_str, math_fontfamily='dejavusans', fontproperties='Arial').get_fontproperties() + assert prop4.get_math_fontfamily() == 'dejavusans' + + prop5 = fig.text(0.1, 0.5, test_str, font='Arial', math_fontfamily='dejavusans').get_fontproperties() + assert prop5.get_math_fontfamily() == 'dejavusans' + + prop6 = fig.text(0.1, 0.6, test_str, fontproperties='Arial', math_fontfamily='dejavusans').get_fontproperties() + assert prop6.get_math_fontfamily() == 'dejavusans' + + fig.savefig(buff, format="svg") From 842fc882fc3f79027ac1dc8e2920acd1b1885964 Mon Sep 17 00:00:00 2001 From: ain-soph Date: Wed, 28 Apr 2021 20:30:50 -0400 Subject: [PATCH 07/16] split into 2 test methods --- lib/matplotlib/tests/test_mathtext.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/matplotlib/tests/test_mathtext.py b/lib/matplotlib/tests/test_mathtext.py index 60f7f71c1252..951b8083f46f 100644 --- a/lib/matplotlib/tests/test_mathtext.py +++ b/lib/matplotlib/tests/test_mathtext.py @@ -399,16 +399,23 @@ def test_default_math_fontfamily(): prop2 = fig.text(0.1, 0.2, test_str, fontproperties='Arial').get_fontproperties() assert prop2.get_math_fontfamily() == 'cm' - prop3 = fig.text(0.1, 0.3, test_str, math_fontfamily='dejavusans', font='Arial').get_fontproperties() - assert prop3.get_math_fontfamily() == 'dejavusans' +def test_argument_order(): + mpl.rcParams['mathtext.fontset'] = 'cm' + test_str = r'Foo: $\alpha_{i+1}^j = {\rm sin}(2\pi f_j t_i) e^{-5 t_i/\tau}$' - prop4 = fig.text(0.1, 0.4, test_str, math_fontfamily='dejavusans', fontproperties='Arial').get_fontproperties() - assert prop4.get_math_fontfamily() == 'dejavusans' + buff = io.BytesIO() + fig, ax = plt.subplots() + + prop1 = fig.text(0.1, 0.1, test_str, math_fontfamily='dejavusans', font='Arial').get_fontproperties() + assert prop1.get_math_fontfamily() == 'dejavusans' - prop5 = fig.text(0.1, 0.5, test_str, font='Arial', math_fontfamily='dejavusans').get_fontproperties() - assert prop5.get_math_fontfamily() == 'dejavusans' + prop2 = fig.text(0.1, 0.2, test_str, math_fontfamily='dejavusans', fontproperties='Arial').get_fontproperties() + assert prop2.get_math_fontfamily() == 'dejavusans' - prop6 = fig.text(0.1, 0.6, test_str, fontproperties='Arial', math_fontfamily='dejavusans').get_fontproperties() - assert prop6.get_math_fontfamily() == 'dejavusans' + prop3 = fig.text(0.1, 0.3, test_str, font='Arial', math_fontfamily='dejavusans').get_fontproperties() + assert prop3.get_math_fontfamily() == 'dejavusans' + + prop4 = fig.text(0.1, 0.4, test_str, fontproperties='Arial', math_fontfamily='dejavusans').get_fontproperties() + assert prop4.get_math_fontfamily() == 'dejavusans' fig.savefig(buff, format="svg") From 912a7cf8feb340b1e3e31dd0d52f613a3f74d7c0 Mon Sep 17 00:00:00 2001 From: ain-soph Date: Wed, 28 Apr 2021 20:32:24 -0400 Subject: [PATCH 08/16] fix test --- lib/matplotlib/tests/test_mathtext.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/tests/test_mathtext.py b/lib/matplotlib/tests/test_mathtext.py index 951b8083f46f..b2bae37d536c 100644 --- a/lib/matplotlib/tests/test_mathtext.py +++ b/lib/matplotlib/tests/test_mathtext.py @@ -395,10 +395,11 @@ def test_default_math_fontfamily(): prop1 = fig.text(0.1, 0.1, test_str, font='Arial').get_fontproperties() assert prop1.get_math_fontfamily() == 'cm' - prop2 = fig.text(0.1, 0.2, test_str, fontproperties='Arial').get_fontproperties() assert prop2.get_math_fontfamily() == 'cm' + fig.savefig(buff, format="svg") + def test_argument_order(): mpl.rcParams['mathtext.fontset'] = 'cm' test_str = r'Foo: $\alpha_{i+1}^j = {\rm sin}(2\pi f_j t_i) e^{-5 t_i/\tau}$' @@ -408,13 +409,10 @@ def test_argument_order(): prop1 = fig.text(0.1, 0.1, test_str, math_fontfamily='dejavusans', font='Arial').get_fontproperties() assert prop1.get_math_fontfamily() == 'dejavusans' - prop2 = fig.text(0.1, 0.2, test_str, math_fontfamily='dejavusans', fontproperties='Arial').get_fontproperties() assert prop2.get_math_fontfamily() == 'dejavusans' - prop3 = fig.text(0.1, 0.3, test_str, font='Arial', math_fontfamily='dejavusans').get_fontproperties() assert prop3.get_math_fontfamily() == 'dejavusans' - prop4 = fig.text(0.1, 0.4, test_str, fontproperties='Arial', math_fontfamily='dejavusans').get_fontproperties() assert prop4.get_math_fontfamily() == 'dejavusans' From 8a47e03a684a737c76ca53e4d71889e6695f5dc6 Mon Sep 17 00:00:00 2001 From: Ren Pang Date: Thu, 29 Apr 2021 13:37:07 -0400 Subject: [PATCH 09/16] Update font_manager.py --- lib/matplotlib/font_manager.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/matplotlib/font_manager.py b/lib/matplotlib/font_manager.py index 05c3844bc5ef..e1867757ac6a 100644 --- a/lib/matplotlib/font_manager.py +++ b/lib/matplotlib/font_manager.py @@ -648,7 +648,7 @@ def __init__(self, self._stretch = rcParams['font.stretch'] self._size = rcParams['font.size'] self._file = None - self._math_fontfamily = None + self.set_math_fontfamily(math_fontfamily) if isinstance(family, str): # Treat family as a fontconfig pattern if it is the only @@ -656,7 +656,6 @@ def __init__(self, if (style is None and variant is None and weight is None and stretch is None and size is None and fname is None): self.set_fontconfig_pattern(family) - self.set_math_fontfamily(math_fontfamily) return self.set_family(family) @@ -666,7 +665,6 @@ def __init__(self, self.set_stretch(stretch) self.set_file(fname) self.set_size(size) - self.set_math_fontfamily(math_fontfamily) @classmethod def _from_any(cls, arg): From 5b00dfb83a18233e72355a4ee814d32d0d86dde9 Mon Sep 17 00:00:00 2001 From: Ren Pang Date: Wed, 12 May 2021 14:34:05 -0400 Subject: [PATCH 10/16] Update test_mathtext.py --- lib/matplotlib/tests/test_mathtext.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/tests/test_mathtext.py b/lib/matplotlib/tests/test_mathtext.py index b2bae37d536c..6e09c183ff3b 100644 --- a/lib/matplotlib/tests/test_mathtext.py +++ b/lib/matplotlib/tests/test_mathtext.py @@ -386,34 +386,44 @@ def test_math_fontfamily(): fig.text(0.2, 0.3, r"$This\ text\ should\ have\ another$", size=24, math_fontfamily='stix') + def test_default_math_fontfamily(): mpl.rcParams['mathtext.fontset'] = 'cm' - test_str = r'Foo: $\alpha_{i+1}^j = {\rm sin}(2\pi f_j t_i) e^{-5 t_i/\tau}$' + test_str = r'abc$abc\alpha$' buff = io.BytesIO() fig, ax = plt.subplots() prop1 = fig.text(0.1, 0.1, test_str, font='Arial').get_fontproperties() assert prop1.get_math_fontfamily() == 'cm' - prop2 = fig.text(0.1, 0.2, test_str, fontproperties='Arial').get_fontproperties() + prop2 = fig.text(0.2, 0.2, test_str, fontproperties='Arial').get_fontproperties() assert prop2.get_math_fontfamily() == 'cm' fig.savefig(buff, format="svg") + def test_argument_order(): mpl.rcParams['mathtext.fontset'] = 'cm' - test_str = r'Foo: $\alpha_{i+1}^j = {\rm sin}(2\pi f_j t_i) e^{-5 t_i/\tau}$' + test_str = r'abc$abc\alpha$' buff = io.BytesIO() fig, ax = plt.subplots() - prop1 = fig.text(0.1, 0.1, test_str, math_fontfamily='dejavusans', font='Arial').get_fontproperties() + text1 = fig.text(0.1, 0.1, test_str, + math_fontfamily='dejavusans', font='Arial') + prop1 = text1.get_fontproperties() assert prop1.get_math_fontfamily() == 'dejavusans' - prop2 = fig.text(0.1, 0.2, test_str, math_fontfamily='dejavusans', fontproperties='Arial').get_fontproperties() + text2 = fig.text(0.2, 0.2, test_str, + math_fontfamily='dejavusans', fontproperties='Arial') + prop2 = text2.get_fontproperties() assert prop2.get_math_fontfamily() == 'dejavusans' - prop3 = fig.text(0.1, 0.3, test_str, font='Arial', math_fontfamily='dejavusans').get_fontproperties() + text3 = fig.text(0.3, 0.3, test_str, + font='Arial', math_fontfamily='dejavusans') + prop3 = text3.get_fontproperties() assert prop3.get_math_fontfamily() == 'dejavusans' - prop4 = fig.text(0.1, 0.4, test_str, fontproperties='Arial', math_fontfamily='dejavusans').get_fontproperties() + text4 = fig.text(0.4, 0.4, test_str, + fontproperties='Arial', math_fontfamily='dejavusans') + prop4 = text4.get_fontproperties() assert prop4.get_math_fontfamily() == 'dejavusans' fig.savefig(buff, format="svg") From 45800078eb58ce34037baf4c0a12309a387944ef Mon Sep 17 00:00:00 2001 From: Ren Pang Date: Wed, 12 May 2021 15:07:23 -0400 Subject: [PATCH 11/16] Update test_mathtext.py --- lib/matplotlib/tests/test_mathtext.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_mathtext.py b/lib/matplotlib/tests/test_mathtext.py index 6e09c183ff3b..d50c10766996 100644 --- a/lib/matplotlib/tests/test_mathtext.py +++ b/lib/matplotlib/tests/test_mathtext.py @@ -399,7 +399,7 @@ def test_default_math_fontfamily(): prop2 = fig.text(0.2, 0.2, test_str, fontproperties='Arial').get_fontproperties() assert prop2.get_math_fontfamily() == 'cm' - fig.savefig(buff, format="svg") + fig.draw_no_output() def test_argument_order(): @@ -426,4 +426,4 @@ def test_argument_order(): prop4 = text4.get_fontproperties() assert prop4.get_math_fontfamily() == 'dejavusans' - fig.savefig(buff, format="svg") + fig.draw_no_output() From 8f67ef5e0aab170916733a4e8577c4d9bc9e1d5e Mon Sep 17 00:00:00 2001 From: Ren Pang Date: Thu, 13 May 2021 17:16:32 -0400 Subject: [PATCH 12/16] Update test_mathtext.py --- lib/matplotlib/tests/test_mathtext.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/matplotlib/tests/test_mathtext.py b/lib/matplotlib/tests/test_mathtext.py index d50c10766996..9ea19e417135 100644 --- a/lib/matplotlib/tests/test_mathtext.py +++ b/lib/matplotlib/tests/test_mathtext.py @@ -390,13 +390,13 @@ def test_math_fontfamily(): def test_default_math_fontfamily(): mpl.rcParams['mathtext.fontset'] = 'cm' test_str = r'abc$abc\alpha$' - - buff = io.BytesIO() fig, ax = plt.subplots() - prop1 = fig.text(0.1, 0.1, test_str, font='Arial').get_fontproperties() + text1 = fig.text(0.1, 0.1, test_str, font='Arial') + prop1 = text1.get_fontproperties() assert prop1.get_math_fontfamily() == 'cm' - prop2 = fig.text(0.2, 0.2, test_str, fontproperties='Arial').get_fontproperties() + text1 = fig.text(0.2, 0.2, test_str, fontproperties='Arial') + prop2 = text2.get_fontproperties() assert prop2.get_math_fontfamily() == 'cm' fig.draw_no_output() @@ -405,8 +405,6 @@ def test_default_math_fontfamily(): def test_argument_order(): mpl.rcParams['mathtext.fontset'] = 'cm' test_str = r'abc$abc\alpha$' - - buff = io.BytesIO() fig, ax = plt.subplots() text1 = fig.text(0.1, 0.1, test_str, From 0d1a388a68ff61eec6ddfbdc3a00e3115dbae967 Mon Sep 17 00:00:00 2001 From: Ren Pang Date: Sat, 15 May 2021 21:07:02 -0400 Subject: [PATCH 13/16] Update test_mathtext.py --- lib/matplotlib/tests/test_mathtext.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_mathtext.py b/lib/matplotlib/tests/test_mathtext.py index 9ea19e417135..29b3ea61464a 100644 --- a/lib/matplotlib/tests/test_mathtext.py +++ b/lib/matplotlib/tests/test_mathtext.py @@ -395,7 +395,7 @@ def test_default_math_fontfamily(): text1 = fig.text(0.1, 0.1, test_str, font='Arial') prop1 = text1.get_fontproperties() assert prop1.get_math_fontfamily() == 'cm' - text1 = fig.text(0.2, 0.2, test_str, fontproperties='Arial') + text2 = fig.text(0.2, 0.2, test_str, fontproperties='Arial') prop2 = text2.get_fontproperties() assert prop2.get_math_fontfamily() == 'cm' From 356c8dbaff96d1339c06f8ffea0c70227d3e32f0 Mon Sep 17 00:00:00 2001 From: Ren Pang Date: Mon, 17 May 2021 22:05:00 -0400 Subject: [PATCH 14/16] add a whitespace --- lib/matplotlib/tests/test_mathtext.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/matplotlib/tests/test_mathtext.py b/lib/matplotlib/tests/test_mathtext.py index d5252a6b174c..7aa406ec5d17 100644 --- a/lib/matplotlib/tests/test_mathtext.py +++ b/lib/matplotlib/tests/test_mathtext.py @@ -426,6 +426,7 @@ def test_argument_order(): fig.draw_no_output() + def test_mathtext_cmr10_minus_sign(): # cmr10 does not contain a minus sign and used to issue a warning # RuntimeWarning: Glyph 8722 missing from current font. From 38560bc2a795e85e0784cee9f5bfff2ce536fbec Mon Sep 17 00:00:00 2001 From: Ren Pang Date: Thu, 20 May 2021 02:04:52 -0400 Subject: [PATCH 15/16] use cbook.normalize_kwargs --- lib/matplotlib/text.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index c99fd5631a2d..aca632e3366f 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -174,13 +174,12 @@ def update(self, kwargs): # docstring inherited # make a copy so we do not mutate user input! kwargs = dict(kwargs) + kwargs = cbook.normalize_kwargs(kwargs, Text) sentinel = object() # bbox can be None, so use another sentinel. # Update fontproperties first, as it has lowest priority. - alias_map = ["fontproperties", *self._alias_map["fontproperties"]] - for alias in alias_map: - fontproperties = kwargs.pop(alias, sentinel) - if fontproperties is not sentinel: - self.set_fontproperties(fontproperties) + fontproperties = kwargs.pop("fontproperties", sentinel) + if fontproperties is not sentinel: + self.set_fontproperties(fontproperties) # Update bbox last, as it depends on font properties. bbox = kwargs.pop("bbox", sentinel) super().update(kwargs) From f6f0686e84533153d5cf0389c7a95e5d4d34f0e0 Mon Sep 17 00:00:00 2001 From: Ren Pang Date: Thu, 20 May 2021 02:07:40 -0400 Subject: [PATCH 16/16] no need to copy (normalize_kwargs already copy it) --- lib/matplotlib/text.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index aca632e3366f..50b26c9166ad 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -172,8 +172,6 @@ def __init__(self, def update(self, kwargs): # docstring inherited - # make a copy so we do not mutate user input! - kwargs = dict(kwargs) kwargs = cbook.normalize_kwargs(kwargs, Text) sentinel = object() # bbox can be None, so use another sentinel. # Update fontproperties first, as it has lowest priority.