Using% matplotlib laptop after% matplotlib inline in Jupyter Notebook does not work

I am using a Jupyter Notebook to build picchart drawings.

In the first cell with my code, I have a magic command %matplotlib inline, and after this magic command I run my code, everything works fine, and my figure displays.

But in the second cell , when I set %matplotlib notebookfor interactive charting, my figure will not be displayed after starting this second cell.

I need to restart the kernel and restart the cell using %matplotlib notebookand not run the command %matplotlib inlinebefore that.

Here is my code for the first cell with %matplotlib inline, which does a fine:

import matplotlib.pyplot as plt

%matplotlib inline

labels = "No", "Yes"
sizes = [100, 50]

fig, ax = plt.subplots(figsize=(6, 6))

_, texts, autotexts = ax.pie(sizes, explode=explode, labels=labels, colors=colors, autopct='%1.1f%%',
             shadow=False, startangle=90)

ax.axis('equal')

, %matplotlib inline %matplotlib notebook. , ​​ .

?

+14
3

. pyplot jupyter. , , pyplot .

%matplotlib... pyplot.

:

%matplotlib inline
import matplotlib.pyplot as plt
plt.plot([1,1.6,3])

:

%matplotlib notebook
#calling it a second time may prevent some graphics errors
%matplotlib notebook  
import matplotlib.pyplot as plt
plt.plot([1,1.6,3])

enter image description here

+20

: , backend jupyter. , , matplotlib, .

, , matplotlib.pyplot.switch_backend(newbackend), . matplotlib docs:

matplotlib.pyplot.switch_backend (newbackend)

. , , , . , PostScript, ipython, PS, , . GUI- , .

, ​​ , , matplotlib .

GUI-. , Qt Tkinter . , jupyter.

. : backend matplotlib/Python

+3

In a Jupyter notebook, you must specify the matplotlib notebook in the same line as the one you want to run. Even if you type inline and then notepad, it still won't work. It should be on the same line as the code you want to display.

0
source

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


All Articles