diff --git a/lib/matplotlib/tests/baseline_images/test_patheffects/spaces_and_newlines.png b/lib/matplotlib/tests/baseline_images/test_patheffects/spaces_and_newlines.png new file mode 100644 index 000000000000..9dd4c1e8d7ff Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_patheffects/spaces_and_newlines.png differ diff --git a/lib/matplotlib/tests/test_patheffects.py b/lib/matplotlib/tests/test_patheffects.py index d0f4fabf4b5c..6e09f4e37d6d 100644 --- a/lib/matplotlib/tests/test_patheffects.py +++ b/lib/matplotlib/tests/test_patheffects.py @@ -189,3 +189,16 @@ def test_tickedstroke(): ax3.set_xlim(0, 4) ax3.set_ylim(0, 4) + + +@image_comparison(['spaces_and_newlines.png'], remove_text=True) +def test_patheffects_spaces_and_newlines(): + ax = plt.subplot() + s1 = " " + s2 = "\nNewline also causes problems" + text1 = ax.text(0.5, 0.75, s1, ha='center', va='center', size=20, + bbox={'color': 'salmon'}) + text2 = ax.text(0.5, 0.25, s2, ha='center', va='center', size=20, + bbox={'color': 'thistle'}) + text1.set_path_effects([path_effects.Normal()]) + text2.set_path_effects([path_effects.Normal()]) diff --git a/lib/matplotlib/textpath.py b/lib/matplotlib/textpath.py index 9b14e79ec2d2..4a192a443d13 100644 --- a/lib/matplotlib/textpath.py +++ b/lib/matplotlib/textpath.py @@ -131,6 +131,11 @@ def get_text_path(self, prop, s, ismath=False): verts.extend(verts1) codes.extend(codes1) + # Make sure an empty string or one with nothing to print + # (e.g. only spaces & newlines) will be valid/empty path + if not verts: + verts = np.empty((0, 2)) + return verts, codes def get_glyphs_with_font(self, font, s, glyph_map=None,