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

Skip to content

[Bug]: WebAgg figures can become permanently broken on displays with device pixel ratio of 1 #32144

Description

@johnwduggan

Bug summary

After a WebAgg figure has been loaded on a display with a device pixel ratio not equal to 1, it permanently renders incorrectly on page load on displays with device pixel ratio equal to 1.

Code for reproduction

import matplotlib
import matplotlib.pyplot as plt

matplotlib.use("WebAgg")

fig, ax = plt.subplots()
ax.plot([1, 2, 3], [4, 5, 6])
ax.set_title("Test Plot")
plt.show(block=True)

Actual outcome

  1. Open a WebAgg figure in a browser on a display with a device pixel ratio of 1 (this renders correctly)
  2. Move to a display with a device pixel ratio of 2 and refresh (this renders correctly)
  3. Move back to the original display and refresh (this breaks). Only the top-left quadrant of the figure renders and can only be fixed by restarting the server.

Final screenshot:
Image

Expected outcome

I'd expect the final step to reset the device pixel ratio to 1 and render the figure at a correct size.

Image

Additional information

In mpl.js, there is a condition that skips setting the device pixel ratio when it's equal to 1. This condition serves no functional purpose as far as I can tell, so I think it should be removed (happy to submit a PR if whoever reads this agrees). :)

Relevant line of code: https://github.com/matplotlib/matplotlib/blob/main/lib/matplotlib/backends/web_backend/js/mpl.js#L67

Operating system

MacOS

Matplotlib Version

3.10.8

Matplotlib Backend

WebAgg

Python version

3.13.14

Jupyter version

No response

Installation

pixi

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions