How can I tell matplotlib/jupyter to make a non-interactive plot using %matplotlib notebook?
Currently, I'm using %matplotlib notebook for some things, but would prefer to use regular %matplotlib inline elsewhere. Is there a way to specify non-interactive plots?
Related
In Jupyter, if the last statement in a cell returns a matplotlib.Figure, the figure is displayed.
One can perform a similar trick with custom classes by providing a _repr_png_ function in that class. However, matplotlib Figures do not provide this function. This makes me wonder. How does Jupyter "know" what to do with a matplotlib figure?
How does Jupyter "know" what to do with a matplotlib figure?
In the inline backend, this is achieved by registering a function to show changed figures (flush_figures) with the post_execute event in IPython, see configure_inline_support.
How can I make my 3d plots using PyPlot interactive from Jupyter notebook?
I have a surface plot:
using PyPlot
x=1:0.1:10
y=x'
z=x.^2 + y.^2
surf(x,y,z)
but it is in a fixed window in my notebook.
Use: PyPlot; pygui(true) to open a standalone GUI window.
Try running %matplotlib notebook and see the output:
The analogue of IPython's %matplotlib in Julia is to use the PyPlot package, which gives a Julia interface to Matplotlib including inline plots in IJulia notebooks. (The equivalent of numpy is already loaded by default in Julia.)
Given PyPlot, the analogue of %matplotlib inline is using PyPlot, since PyPlot defaults to inline plots in IJulia.
To enable separate GUI windows in PyPlot, analogous to %matplotlib, do using PyPlot; pygui(true). To specify a particular gui backend, analogous to %matplotlib gui, you can either do using PyPlot; pygui(:gui); using PyPlot; pygui(true) (where gui is wx, qt, tk, or gtk), or you can do ENV["MPLBACKEND"]=backend; using PyPlot; pygui(true) (where backend is the name of a Matplotlib backend, like tkagg).
For more options, see the PyPlot documentation.
Is there a way to have the plots created inside Jupyter Notebook using matplotlib to appear on a separate pop-up screen that would allow you to expand/shrink the image by hand? I've tried experimenting with (%matplotlib notebook) but that didn't really do the trick.
Just wondering if this is possible.
Just use an interactive backend. This works for me:
import matplotlib.pyplot as plt
%matplotlib tk
plt.plot([1, 2])
The notebook (nbagg) backend also allows for expand/shrink by hand. It has some rough edges though.
The tkinter backend is a bit buggy (windows 10, python 3).
I used %matplotlib qt for the matplotlib plot that we are all used to.
If I try to use in a jupyter notebook
%matplotlib notebook
import seaborn as sns
...
plt.grid()
The the grid is not visible.
If I try the same in plain python (not jupyter notebook, without %matplotlib), the grid is fine.
Calling plt.grid() with no arguments toggles the grid state. Because there is a grid in the default seaborn style, you are turning it off.
I am running code written with PyQt4 which uses matplotlib's Qt4Agg backend for showing live plots in windows. At the same time, I would like to use matplotlib in background thread to produce (different) figures which are only saved to file, not shown on the screen.
I can use Qt4Agg in the background thread, but I am getting a bunch of
QPixmap: It is not safe to use pixmaps outside the GUI thread
warnings, and also crashes in some cases.
As far as I see, matplotlib currently supports using only one backend at any given time (which can be changed via switch_backend, but that closes all existing figures). Is there some way to work around this limitation, and to assign per-figure backend?
To my knowledge, only if you don't use the pyplot interface.
For instance, using the full OO interface for a simple plot:
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
fig = Figure()
canvas = FigureCanvas(fig)
ax = fig.add_subplot(1,1,1)
ax.plot([1,2,3])
canvas.print_figure('test.png')
HTH