GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — [Bug]: Changing text.latex.preamble does not invalidate cached usetex text metrics · Issue #32413 · matplotlib/matplotlib Open Labels DescriptionBug summaryWith usetex, Matplotlib caches text metrics without the LaTeX preamble in the cache key. After text.latex.preamble changes, redrawing an existing figure keeps the old text widths. On 3.10 and later, a new Text in the same figure also gets the old width. Only a new figure measures the text correctly. Code for reproductionimport matplotlib matplotlib.use("Agg") import matplotlib as mpl import matplotlib.pyplot as plt fig, ax = plt.subplots() text = ax.text(0.1, 0.5, "Hmx minimum", usetex=True, fontsize=30) fig.canvas.draw() print("before:", text.get_window_extent().width) with mpl.rc_context({"text.latex.preamble": r"\usepackage{helvet}"}): fig.canvas.draw() print("after, same Text:", text.get_window_extent().width) new = ax.text(0.1, 0.2, "Hmx minimum", usetex=True, fontsize=30) fig.canvas.draw() print("after, new Text in the same figure:", new.get_window_extent().width) fig2, ax2 = plt.subplots() fresh = ax2.text(0.1, 0.5, "Hmx minimum", usetex=True, fontsize=30) fig2.canvas.draw() print("after, new figure:", fresh.get_window_extent().width) Actual outcomeOn 3.11.2 (3.10.9 gives the same):
On 3.5.3, the new Text in the same figure measures 264.755 and the same Text keeps 240.825. Expected outcomeAll three "after" widths should be 264.755, the width of the text set in Helvetica. Additional information
A possible fix: when I found this while adding usetex support to curved-text, a library that draws text along curves; its labels inherit the same stale widths. Operating systemWindows 11 Matplotlib Version3.11.2 (also 3.10.9 and 3.5.3) Matplotlib BackendAgg Python version3.13.3 Jupyter versionnone Installationpip Activity
MetadataMetadataAssigneesLabelsTypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |