1

I'd like to know if a matplotlib chart be interactive, ie when you right click on a graph bar, a context menu opens, then you click one of the menu items and change the value of y value or you drag the top edge of the bar with mouse and it becomes taller etc,

In other words, can a matplotlib chart act like a GUI?

Lee
  • 29,398
  • 28
  • 117
  • 170
alwbtc
  • 28,057
  • 62
  • 134
  • 188

3 Answers3

2

yep, though I should warn you: matplotlib isn't the best choice for interactive tasks. Depends on your tasks you may face performance or UX issues..

Take a look at the Chaco. It was designed for the creation of complex interactive plots.

Chaco

Bruno Gelb
  • 5,322
  • 8
  • 35
  • 50
1

Yes.


Matplotlib is based on Tkinter, so you can do all sorts GUI related things with it. For an example of how you can embed matplotlib in a Tkinter GUI see here:

http://matplotlib.org/examples/user_interfaces/embedding_in_tk.html

Similarly for the functionality you are describing, you require plots that know when they've been clicked on (or mouse-overed) and that you can add callback events to. For that, the first place to look would be picker events:

http://matplotlib.org/examples/event_handling/pick_event_demo.html

ebarr
  • 7,704
  • 1
  • 29
  • 40
  • Thanks, but can I pop-up a right-click menu when I click on for example a bar? If yes, can this chart be placed on a wxpython GUI? – alwbtc Apr 17 '14 at 09:04
  • The right-click menu would probably require some custom code. Have a look at: http://stackoverflow.com/questions/19898115/wxpython-with-matplotlib and also http://stackoverflow.com/questions/12014210/python-tkinter-app-adding-a-right-click-context-menu – ebarr Apr 17 '14 at 09:46
  • [Right click menu](https://github.com/PySimpleGUI/PySimpleGUI/blob/master/DemoPrograms/Demo_Menus.py) is very easy to do with PySimpleGUI (based on tkinter). There is also some [demo code](https://github.com/PySimpleGUI/PySimpleGUI/tree/master/DemoPrograms) how to use PySimpleGUI with Matplotlib (see Demo_Matplotlib_*.py). – rtrrtr Apr 13 '21 at 09:54
1

As an alternative to some of the other ideas I would propose the Ipython notebook. For me it is the easiest way to do some of the things your asking about without having to get into Tkinter etc.

From Ipython 2.* onward there are interactive widgets allowing you to interact with the kernel from a GUI. I am not an expert in any sense so it is probably best explain by Fernando Perez himself.

Here is an example of interaction when solving the Lorenz differential equation demonstrating a chaotic system. This is accessible in the example of the ipython directory.

enter image description here

Greg
  • 11,654
  • 3
  • 44
  • 50