question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Render stored Matplotlib png output as a fallback when opening a notebook

See original GitHub issue

Actual behaviour

With the current ipympl and using %matplotlib widget as a backend VS code can render this example without issues:

%matplotlib widget

from matplotlib import pyplot as plt

fig, ax = plt.subplots()
ax.plot([0,1,2], [2,3,4] ,"o-")

image

Though, when saving and reloading the notebook file no image is shown (although a static image is available):

image

Expected behaviour

The small </> icon on the left allows to change the mimetype representation. When this is changed manually to png the alternative widget representation that was previously saved is shown correctly:

image

So VS code does not recognize that without a running/current widget available that the png static representation should be shown instead.

Environment data

  • VS Code version: 1.63.2
  • Jupyter Extension version v2021.11.1001550889
  • Python Extension version v2021.12.1559732655
  • OS (Windows | Mac | Linux distro) and version: Windows 10
  • Python and/or Anaconda version: 3.9.9
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): conda
  • Jupyter server running: Local

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mjbvzcommented, Sep 21, 2022

@rebornix To support this, we need to transfer the entire output to the webview. Today I believe we just send over the output for the selected item mime type

That would allow us to fallback to a different renderer if we can’t find one for the current mime type

Let’s look into this for October

1reaction
rchiodocommented, Jan 4, 2022

Thanks for the bug. VS code doesn’t allow for a fallback mimetype. On reload it just uses the widget data as that’s what was selected before.

We don’t support reloading widgets at the moment (see this bug for more info: https://github.com/microsoft/vscode-jupyter/issues/5424#issuecomment-815065089)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Matplotlib (pyplot) savefig outputs blank image - Stack Overflow
In your code, 'tesssttyyy.png' is blank because it is saving the new figure, to which nothing has been plotted. Share.
Read more >
Customizing Matplotlib with style sheets and rcParams
Another way to change the visual appearance of plots is to set the rcParams in a so-called style sheet and import that style...
Read more >
matplotlib - The Architecture of Open Source Applications
Because the PNG output matplotlib produces also uses the agg renderer, ... of Axes methods that create plot objects and store them in...
Read more >
User and Workspace Settings - Visual Studio Code
Similar to User Settings, Workspace Settings are also stored in a settings.json file, which you can edit directly via the Preferences: Open Workspace ......
Read more >
2 ways to improve the default resolution of matplotlib plots ...
2 ways to improve the default resolution of matplotlib plots rendered in Jupyter notebooks · Get improved resolution inline and on export.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found