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

Image results are not shown in the PDF if %matplotlib magic commands are used #34

Closed
Cube707 opened this issue Oct 8, 2021 · 2 comments

Comments

@Cube707
Copy link

Cube707 commented Oct 8, 2021

Hello there, loving your Project so far.
I just tried using it to export some explanations on how to use matplotlib and realized the following:

Problem:

When using magic comments like %matplotlib notebook or %matplotlib widget to produce interactive plot windows, the results are not displayed in the final PDF.
This is not a huge issue as you can comment out these commands and run the notebook again to get it into a state where the export works, but I feel this is an unnecessary step that could be avoided.

Example code:

Here is a example cell so you can test it yourselfe:

%matplotlib widget

from matplotlib import pyplot as plt
from math import sin

x = list(range(100))
y = [sin(x) for x in x]

plt.plot(x,y)

some analysis:

Looking at the actual json data, it seems like the image is just there in the same form in both cases. So from my perspective the same functionality could be used to display both image types

Json representation without magic:

"outputs": [
    {
        "output_type": "execute_result",
        "data": {
            "text/plain": [
                "[<matplotlib.lines.Line2D at 0x229ac10ba30>]"
            ]
        },
        "metadata": {},
        "execution_count": 1
    },
    {
        "output_type": "display_data",
        "data": {
            "image/png": "loads of base64...", //here is the actuall image 
            "text/plain": [
                "<Figure size 432x288 with 1 Axes>"
            ]
        },
        "metadata": {
            "needs_background": "light"
        }
    }
],

Json representation with magic:

"outputs": [
    {
        "output_type": "execute_result",
        "data": {
            "text/plain": [
                "[<matplotlib.lines.Line2D at 0x229aef84dc0>]"
            ]
        },
        "metadata": {},
        "execution_count": 2
    },
    {
        "output_type": "display_data",
        "data": {
            "application/vnd.jupyter.widget-view+json": {
                "version_major": 2,
                "version_minor": 0,
                "model_id": "c9dfc6ced3c74d28882947a564d6eb03"
            },
            "image/png": "loads of base64...", //more or less the same as above
            "text/plain": [
                "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
            ]
        },
        "metadata": {}
    }
],
@Cube707
Copy link
Author

Cube707 commented Oct 8, 2021

seems to be an upstream problem with the html exporter. Should I close this here or do you want to keep it open?

@Cube707
Copy link
Author

Cube707 commented Nov 14, 2021

closed upstream by jupyter/nbconvert#1664

@Cube707 Cube707 closed this as completed Nov 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant