Interactive series selection on matplotlib chart

I was looking for a way to choose which series are visible on the chart, after creating the plot.

I need this because I often have stories with many episodes. there are too many of them to build at the same time, and I need to quickly and interactively choose which series are visible. Ideally, there will be a window with a list of episodes in the plot and flags, where a series with a flag is visible.

Does anyone know if this has already been implemented somewhere? If not, can someone help me, how can I do it myself?

Thanks!

Lobster

+8
python matplotlib
source share
3 answers

It all depends on how much effort you are willing to make and what the exact requirements are, but you can bet that it has already been implemented somewhere :-)

If the goal is not to clutter up the image, it may be enough to use the built-in features; you can find the corresponding code in the matplotlib example library:

If you really want to have a user interface so that you can protect performance by limiting the amount of graphs / data, you usually use a set of GUI tools such as GTK, QT or WX. Check out a few articles and sample code here:

+8
source share

A checklist will be good if you have multiple plots or fewer, but for more plots, a pop-up menu is likely to be better. I'm not sure if this is possible with matplotlib.

The way I did this was to use the slider to select a chart from the list - basically you use the slider to set the index of the series that should be displayed. I had several hundred episodes per dataset, so this was a good way to take a quick look at them.

My setup code was something like this:

fig = pyplot.figure() slax = self.fig.add_axes((0.1,0.05,0.35,0.05)) sl = matplotlib.widgets.Slider(slax, "Trace #", 0, len(plotlist), valinit=0.0) def update_trace(): ax.clear() tracenum = int(np.floor(sl.val)) ax.plot(plotlist[tracenum]) fig.canvas.draw() sl.on_changed(update_trace) ax = self.fig.add_axes((0.6, 0.2, 0.35, 0.7)) fig.add_subplot(axes=self.traceax) update_trace() 

Here is an example:

Plot image

+2
source share

Now that plot.ly has opened its libraries, it is really a good choice for interactive graphs in python. See for example: https://plot.ly/python/legend/#legend-names . You can click on the trail of a legend and select / deselect traces.

If you want to embed in an Ipython / Jupyter Notebook, this is also simple: https://plot.ly/ipython-notebooks/gallery/

0
source share

All Articles