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.
Automatically run %matplotlib inline in IPython Notebook
The configuration way
IPython has profiles for configuration, located at ~/.ipython/profile_*
. The default profile is called profile_default
. Within this folder there are two primary configuration files:
ipython_config.py
ipython_kernel_config.py
Add the inline option for matplotlib to ipython_kernel_config.py
:
c = get_config()
# ... Any other configurables you want to set
c.InteractiveShellApp.matplotlib = "inline"
matplotlib vs. pylab
Usage of %pylab
to get inline plotting is discouraged.
It introduces all sorts of gunk into your namespace that you just don't need.
%matplotlib
on the other hand enables inline plotting without injecting your namespace. You'll need to do explicit calls to get matplotlib and numpy imported.
import matplotlib.pyplot as plt
import numpy as np
The small price of typing out your imports explicitly should be completely overcome by the fact that you now have reproducible code.
How to make inline plots in Jupyter Notebook larger?
Yes, play with figuresize
and dpi
like so (before you call your subplot):
fig=plt.figure(figsize=(12,8), dpi= 100, facecolor='w', edgecolor='k')
As @tacaswell and @Hagne pointed out, you can also change the defaults if it's not a one-off:
plt.rcParams['figure.figsize'] = [12, 8]
plt.rcParams['figure.dpi'] = 100 # 200 e.g. is really fine, but slower
How can I open the interactive matplotlib window in IPython notebook?
According to the documentation, you should be able to switch back and forth like this:
In [2]: %matplotlib inline
In [3]: plot(...)
In [4]: %matplotlib qt # wx, gtk, osx, tk, empty uses default
In [5]: plot(...)
and that will pop up a regular plot window (a restart on the notebook may be necessary).
I hope this helps.
jupyter notebook matplotlib show plot and then plot on the origin figure
Update: I actually figured out the answer.
def plot(step):
fig = plt.figure(figsize=(5,5))
ax = plt.axes()
ax.set_xlabel('cat')
ax.set_ylabel('dog')
plt.title("Set of 2 animals")
if step>=1:
x = np.linspace(0, 1.0, 1000)
ax.plot(x, 1.0-x,zorder = 0)
if step>=2:
p0 = 0.5
p1 = 0.5
color = "blue"
textd =0.05
ax.scatter([p0],[p1], color = color,zorder=1)
ax.text(p0+textd, p1+textd, 'tiger',color = color,zorder =2)
plot.show()
should be able to solve the problem.
Related Topics
Getting the Class Name of an Instance
How to Use a Dll File from Python
Plot Logarithmic Axes with Matplotlib in Python
How to Delete a Character from a String Using Python
Getting the Index of the Returned Max or Min Item Using Max()/Min() on a List
How to Access the Ith Column of a Numpy Multidimensional Array
Calling a Python Script with Input Within a Python Script Using Subprocess
How to Handle the Window Close Event in Tkinter
How to Convert a String of Bytes into an Int
Create a Directly-Executable Cross-Platform Gui App Using Python
What Are "First-Class" Objects
How to Format a Decimal to Always Show 2 Decimal Places
How to Delete Items from a Dictionary While Iterating Over It
How to Get the Logical Xor of Two Variables in Python
What Is the Most Efficient Way of Finding All the Factors of a Number in Python