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

Skip to content

Commit 54b17aa

Browse files
authored
Merge pull request #22703 from meeseeksmachine/auto-backport-of-pr-22689-on-v3.5.x
Backport PR #22689 on branch v3.5.x (Fix path_effects to work on text with spaces only)
2 parents 7399791 + 4231c61 commit 54b17aa

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

lib/matplotlib/tests/test_patheffects.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,16 @@ def test_tickedstroke():
189189

190190
ax3.set_xlim(0, 4)
191191
ax3.set_ylim(0, 4)
192+
193+
194+
@image_comparison(['spaces_and_newlines.png'], remove_text=True)
195+
def test_patheffects_spaces_and_newlines():
196+
ax = plt.subplot()
197+
s1 = " "
198+
s2 = "\nNewline also causes problems"
199+
text1 = ax.text(0.5, 0.75, s1, ha='center', va='center', size=20,
200+
bbox={'color': 'salmon'})
201+
text2 = ax.text(0.5, 0.25, s2, ha='center', va='center', size=20,
202+
bbox={'color': 'thistle'})
203+
text1.set_path_effects([path_effects.Normal()])
204+
text2.set_path_effects([path_effects.Normal()])

lib/matplotlib/textpath.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ def get_text_path(self, prop, s, ismath=False):
131131
verts.extend(verts1)
132132
codes.extend(codes1)
133133

134+
# Make sure an empty string or one with nothing to print
135+
# (e.g. only spaces & newlines) will be valid/empty path
136+
if not verts:
137+
verts = np.empty((0, 2))
138+
134139
return verts, codes
135140

136141
def get_glyphs_with_font(self, font, s, glyph_map=None,

0 commit comments

Comments
 (0)