Why do we need %matplotlib inline?
Thanks to @Georgy, fixed the problem. Using matplotlib.get_backend()
, you can see the backend within the notebook is already set to inline by default.module:// ipykernel.pylab.backend_inline
and It turns out that it's working on backend.
Why doesn't '%matplotlib inline' work in python script?
Other answers and comments have sufficiently detailed why %matplotlib inline
cannot work in python scripts.
To solve the actual problem, which is to show the plot in a script, the answer is to use
plt.show()
at the end of the script.
How to run Python Code with '%matplotlib inline'?
A particularly interesting backend, provided by IPython, is the inline backend. This is available only for the Jupyter Notebook and the Jupyter QtConsole. It can be invoked as follows:
%matplotlib inline
With this backend, the output of plotting commands is displayed inline within frontends like the Jupyter notebook, directly below the code cell that produced it. The resulting plots will then also be stored in the notebook document.
if you don't use frontends such as jupyter note book just remove the "%*****inline"
How to make IPython notebook matplotlib plot inline
I used %matplotlib inline
in the first cell of the notebook and it works. I think you should try:
%matplotlib inline
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
You can also always start all your IPython kernels in inline mode by default by setting the following config options in your config files:
c.IPKernelApp.matplotlib=<CaselessStrEnum>
Default: None
Choices: ['auto', 'gtk', 'gtk3', 'inline', 'nbagg', 'notebook', 'osx', 'qt', 'qt4', 'qt5', 'tk', 'wx']
Configure matplotlib for interactive use with the default matplotlib backend.
Related Topics
"Too Many Values to Unpack" Exception
How to Append One String to Another in Python
Most Recent Previous Business Day in Python
Error When Configuring Tkinter Widget: 'Nonetype' Object Has No Attribute
Convert Unix Time to Readable Date in Pandas Dataframe
Access Elementtree Node Parent Node
How to Make a Scatter Plot Colored by Density in Matplotlib
How to Display Custom Values on a Bar Plot
Python - Extracting and Saving Video Frames
How to Run Python Code from Sublime Text 2
Windows Cmd Encoding Change Causes Python Crash
Not Letting the Character Move Out of the Window
How to Check If There Are Duplicates in a Flat List
Color by Column Values in Matplotlib