please I'm working from my office and I have here Anaconda installed on my machine. I have different dataframes that I plot using matplotlib (see example below). I would need the ability to zoom in/out with the mouse without installing gtk or plotly or any additional library.
Is there any simple way to add this feature?
Many thanks
import numpy as np
from numpy.random import randn
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
df = pd.DataFrame(randn(50,4),columns='W X Y Z'.split())
df["X"].plot()
plt.show()
Replace %maptlotlib inline with %matplotlib notebook.
Now you have an interactive figure in your notebook.
Related
When using HoloViews the Matplotlib backend (in JupyterLab) seems to get set by default to Agg and I can't figure out how to set it to an interactive backend. Is there a way to do that?
The following seems to work for Matplotlib on its own, but has no effect on figures rendered with hv.output(... backend='matplotlib'):
import holoviews as hv
import matplotlib as mpl
hv.extension('bokeh', 'matplotlib'
%matplotlib ipympl
What is the correct way to use ipympl as the Matplotlib backend for HoloViews.
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've seen the exact same question around but the answers didn't help me. like those questions:
Cannot show the graphs on ipython notebook
How to make IPython notebook matplotlib plot inline
So I decided to post a question so i could post my code, see if there is anything different... hopefully it's something very dull that I'm missing. although the code runs perfectly in ipython shell. Thanks in advance !
%matplotlib inline
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 3*np.pi, 500)
plt.plot(x, np.sin(x**2))
plt.title('A simple chirp')
plt.show()
PS: I'm using Anaconda distribution, and I launched notebook by the shortcut that comes with it IPython (Python 2.7) Notebook
PS2: the output I get is virtually none.