ipython notebook --pylab inline: zooming of a plot

PythonMatplotlibIpython

Python Problem Overview


Is it possible to zoom into a plot if inline is activated? Especially regarding to 3d-plots rotating and zooming is a necessary feature.

Python Solutions


Solution 1 - Python

You can now use %matplotlib notebook instead of %matplotlib inline and you'll be able to interact with your plots.

Solution 2 - Python

Now thanks to mpld3 it's super easy to enable zooming in inline plots!

All you have to do is install mpld3 (pip install mpld3), and then add this to your notebook:

%matplotlib inline
import mpld3
mpld3.enable_notebook()

Now your plots will get a toolbar menu at the bottom left, in which you can enable mouse zooming :)

Solution 3 - Python

At present, the closest you can come is to redraw it at a larger size using the figsize function. It expects dimensions in inches, which caught me out the first time I tried to use it.

There are some plants for a rich backend that would allow plots to be manipulated live, using HTML5, but I think it will be a few more months before that's ready.

If you're using the notebook on your local computer, for now the easiest option might be not to use inline mode, so the plots pop up as separate windows.

Solution 4 - Python

mpld3 slowed down the execution of my notebooks. I found it better to use the nbagg backend that provides the same interactive tools but also allows to save graphs by the right-click menu:

import matplotlib
matplotlib.use('nbagg')
import matplotlib.pyplot as plt

Solution 5 - Python

Another good example that has emerged recently is to outsource the job to plotly:

> https://plot.ly/python/3d-plots-tutorial/

Let them handle the rendering, panning, and zooming for you!

Solution 6 - Python

matplotlib.use('nbagg') didnt work for me either. I did find mdplt3 quite slow. Instead of zooming, I ended up resizing my figure (making it big), using this post: https://stackoverflow.com/questions/29589119/plot-width-settings-in-ipython-notebook

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionvarantirView Question on Stackoverflow
Solution 1 - PythonJoão AbrantesView Answer on Stackoverflow
Solution 2 - PythonyonilevyView Answer on Stackoverflow
Solution 3 - PythonThomas KView Answer on Stackoverflow
Solution 4 - PythonVictor BettachiniView Answer on Stackoverflow
Solution 5 - PythonAndrew MaoView Answer on Stackoverflow
Solution 6 - PythonRuta DesaiView Answer on Stackoverflow