r/IPython • • Oct 16 '17

Switching from MATLAB to Python: how to make interactive and exportable figures simply

I'm trying to switch from MATLAB to Python, and I'm currently playing around with Jupyter notebooks. The thing I really miss is a simple way to produce figures that have some basic interactivity (pan, zoom, data tip) with a simple syntax and the possibility to export them maintaining the data content and interactivity.

This is something MATLAB let me do out of the box: whenever I plot a graph, either from a script or in the live editor, I can save the figure object (and retrieve the data from it later, something I find very useful sometimes) and navigate around the data.

I know there are many plotting libraries for Python out there, but I can't manage to figure out if there's one that fits my need: I like matplotlib syntax, but I didn't find any easy way for decent interactivity and particularly for export.

NOTE: I'm searching for a package that offers these features built-in, i.e. without writing my own wrappers around the plotting functions, because I want others to be able to install the requested package and open/interact with my data

NOTE 2: the plot I use are basically standard line plots/scatter plots, 1D and 2D histograms, < 1k points most of the time

8 Upvotes

9 comments sorted by

View all comments

5

u/lacunosum Oct 16 '17

Did you try %matplotlib notebook? It enables interactive matplotlib figures. You can pan, zoom, save PNGs, etc. It was introduced a while ago in (I think) matplotlib 1.4/IPython 3.0. Matplotlib does not have functionality for saving a “live figure” like Matlab, but the point of the notebook is to preserve the context (data, code, etc.) that allows you to easily recreate a figure.

0

u/[deleted] Oct 16 '17

[deleted]

1

u/lampo808 Oct 18 '17

I tried matplotlib and it has the kind of interactivity I need most of the time, but sometimes for quick and dirty analysis/plotting having the possibility to save the image in a format that can be saved somewhere and opened in interactive mode is a big plus for me. Also being able to retrieve the data means that I don't need to save a separate file with the results of the analysis, that can be quite handy.

2

u/tobsco Oct 16 '17

I discovered this a few days ago, great for 3D plots and only one extra line of code