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

Skip to content

Fix path_effects to work on text with spaces only #22689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions lib/matplotlib/tests/test_patheffects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()])
5 changes: 5 additions & 0 deletions lib/matplotlib/textpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,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,
Expand Down