Skip to content
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

Download as PDF or Tex does not work with images created inline using %matplotlib notebook #10380

Closed
the-moog opened this issue Feb 5, 2018 · 8 comments
Labels
status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. status: inactive Marked by the “Stale” Github Action third-party integration

Comments

@the-moog
Copy link

the-moog commented Feb 5, 2018

Bug report

(Originaly raised as jupyter/notebook#3295 Though there is some lack of clarity about which parts of Jypyter are managed where - perhaps this itself is a bug?)

Issue:
Download as PDF or Tex does not work with images created inline using %matplotlib notebook

If you create images (graphs etc) using the %matplotlib notebook magic then images created inline are not rendered in Tex or PDF output.

Instead the images is replaced with
<IPython.core.display.Javascript object>
<IPython.core.display.HTML object>

The suggested workround of replacing %matplotlib notebook with %matplotlib inline before using 'Download as' is not convienient as it does not work in all cases.
For example (given below) the figure.set_size_inches methods produces different results.

Also, any dynamic runtime changes to the plots (zoom, pan, etc) are not possible when using inline.

Example code to reproduce the issue

import matplotlib.pyplot as plt
import numpy as np

#%matplotlib inline
%matplotlib notebook

fig = plt.figure()
fig.set_size_inches(9.5,6, forward=True)
plt.plot(np.arange(0,10,0.1))
plt.plot(np.arange(10,0,-0.1))

File -> Download As -> PDF (Via LaTeX)

This issue is also discussed here:
https://stackoverflow.com/questions/35305607/jupyter-notebook-matplotlib-figures-missing-in-exported-pdf

Actual outcome
A PDF document containing code but no pictures

Expected outcome
A PDF document containing code and pictures

Matplotlib version

  • Operating system: Windows 7
  • Matplotlib version: 5.2.2
  • Matplotlib backend (print(matplotlib.get_backend())): nbAgg
  • Python version: 2.7.14
  • Jupyter version (if applicable): 4.4.0
  • Other libraries: n/a

Python was installed as msi from Python website
Everything else installed through pip

@tacaswell
Copy link
Member

attn @mpacer what is the canonical location for nbagg + saving notebooks not play well together?

If you do plt.close('all') before saving does that help?

@tacaswell tacaswell added this to the v3.0 milestone Feb 5, 2018
@efiring
Copy link
Member

efiring commented Feb 12, 2018

I tested with plt.close('all'), and it does not change the result.

@mpacer
Copy link

mpacer commented Feb 12, 2018

I think the issue is that there is no canonical location since the issue could arise in either library.

My intuition is that here for some reason it’s seeing a repr_latex that isn’t doing what we would expect and is dumping the text repr of the object. I think in this case it may be a matplotlib bug. I think the right way to handle this would be to include a repr_png repr_jpeg or repr_latex with a link to the base64 encoded static image. Since the nbagg keeps a channel open to handle updates, you might want to assign these values when the channel is closed.

The issue is that when exporting to LaTeX we can’t really deal with either html or JavaScript and converting to PDF happens via LaTeX.

@tacaswell tacaswell modified the milestones: v3.0, v3.1 Aug 11, 2018
@tacaswell tacaswell modified the milestones: v3.1.0, v3.2.0 Mar 18, 2019
@timhoffm timhoffm modified the milestones: v3.2.0, v3.3.0 Aug 15, 2019
@ghayth82
Copy link

I am facing the same issue, any solution?

@tacaswell
Copy link
Member

@ghayth82 not directly, but the right place to follow the follow-on to this issue is matplotlib/ipympl#16

@jklymak
Copy link
Member

jklymak commented Feb 28, 2020

I don’t think those are the same. That issue refers to the new widgets backend. This issue is using nbagg.

@tacaswell
Copy link
Member

But in both cases the underlying cause is the widget protocol not being quite rich enough or not specified enough for our needs (or we are just using it wrong).

Long term we want to deprecate notebook in favor of ipympl so if we are going to fix it one place we should fix it over there.

@QuLogic QuLogic modified the milestones: v3.3.0, v3.4.0 May 27, 2020
@QuLogic QuLogic modified the milestones: v3.4.0, v3.5.0 Jan 27, 2021
@QuLogic QuLogic modified the milestones: v3.5.0, v3.6.0 Sep 25, 2021
@QuLogic QuLogic modified the milestones: v3.6.0, v3.7.0 Jul 8, 2022
@QuLogic QuLogic modified the milestones: v3.7.0, future releases Jan 24, 2023
Copy link

github-actions bot commented Feb 9, 2024

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Feb 9, 2024
@github-actions github-actions bot added the status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. label Mar 12, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. status: inactive Marked by the “Stale” Github Action third-party integration
Projects
None yet
Development

No branches or pull requests

8 participants