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

Skip to content

bug: path effects in text() change text properties #2889

Closed
@megies

Description

@megies

After encountering strange behavior across matplotlib versions 1.3/1.4 in our image tests in @obspy and a couple of hours of debugging and git bisecting roughly a dozen steps through matplotlib git repo I have pinpointed a problem with path effects..

When using path effects in plt.text() and using plt.savefig("...png") the text properties get changed in a strange way. What I experienced is that font size gets decreased by roughly 25% when I used a path effect on text.

The commit that introduces the bug is 3d31865. The parent commit d5f9876 shows the expected behavior.

The following shows a minimal test case to reproduce:

import matplotlib
matplotlib.use("TKAGG")
import matplotlib.pyplot as plt
import matplotlib.patheffects as PathEffects

plt.text(0, 0, "BAD", size=100,
         #path_effects=[PathEffects.withStroke(linewidth=3,
         #                                     foreground="red")])
         # EDIT: even `Normal()` exposes the bug
         path_effects=[PathEffects.Normal()])
plt.text(0, 0, "        OK", size=100)
plt.savefig("/tmp/patheffects_bug.png")
plt.show()

Note that the plot that shows after savefig has the text with correct size.

Here's the buggy output png image:
patheffects_bug

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions