Jupyter laptop matplotlib figures are missing in exported pdf

When creating a pdf file in a jupyter laptop, everything works fine, but I would like to keep the embedded shapes inside the pdf, as well as the laptop.

Here is my code:

%matplotlib notebook
import matplotlib.pyplot as plt
import numpy as np
from IPython.display import set_matplotlib_formats
set_matplotlib_formats('png', 'pdf')

save_figures = True

x = np.arange(0, 20, 0.1)
y = np.sin(x)
plt.figure()
plt.plot(x, y)
if save_figures:
    plt.savefig('test.png')
plt.show()

The numbers appear on the line, but in pdf what is printed looks like this:

<IPython.core.display.Javascript object>

<IPython.core.display.HTML object>

The same thing appears in pdf if I export from the Internet or use nbconvertto export to pdf from the command line.

Are there any additional commands I need to call in order to get this to work?

+4
source share
1 answer

%matplotlib notebook %matplotlib inline, PDF jupyter nbconvert . %matplotlib notebook , , , LaTeX, PDF.

, - %matplotlib notebook, HTML jupyter nbconvert (jupyter nbconvert --to='html' Test.ipynb), , . HTML PDF -, PDF .

+10

Source: https://habr.com/ru/post/1628052/


All Articles