Pop-up plot label on mouse-over event in matplotlib - python

I am working on a python 2.7+matplotlib+tkinter project where I need to plot up to 60 plots on 1 figure (I can show/hide them then by pressing corresponding legend title and do some other interactive stuff). What I want is to get an annotation box on mouse-over event with the label of current plot. I was thinking about text annotation, but I haven't found any ways to do it interactively.
If it is crucial for an answer - I am working with step and scatter figures. I am ready to provide any information needed, for now I just can't think of something necessary to post here (in terms of source code)

Related

plot multiple figures in the same window but different "tabs" with matplotlib

I know that you can plot multiple figures in the same window by arranging them in a grid layout. However, I want to plot multiple figures, showing only one at a time and be able to move to the next or previous figure with buttons in the UI. I see arrows in the default UI which makes me think there's a way to do this.

How to display a binary state (ON/OFF) in Matplotlib?

I have built a GUI with matplotlib and it contains several plots of values versus time. Now I need a special plot which just shows if a value is on or off (binary state).
Kinda like a control lamp on an analog control panel. I have 5 of those on/off values and I dont know how to do it the best way.
The "lamps" must be updateable because I stream the data from serial and analyze it in real time in my GUI.
I attached a picture where you see my current GUI. In the bottom right corner is now a bar chart, I tried to visualize the ON/OFF state with a bar, but it didn't work well and I wasn't able to animate it.
So yeah, how could I display 5 values with each an ON/OFF state in that area?
Instead of passing via bar charts I would directly plot a number of rectangles and then dynamically change their color.
You can find the documentation for rectangular patches here: http://matplotlib.org/api/patches_api.html#matplotlib.patches.Rectangle
If you need some pointers on how to animate such a patch have a look here:
https://nickcharlton.net/posts/drawing-animating-shapes-matplotlib.html

Changing parameters while plotting in python

I have a code for plotting 3d scatterplot in python that updates after every 2 seconds (plot is dynamic). I wish to be able to adjust the values of some of the parameters on line (while plotting happens) based on which the plotting happens. Is it possible to give a textbox along with the plot from which we can take as input the required parameter value based on which this plot will then be subsequently modified?
Matplotlib does not have a textbox (or other text entry) widget. To use a textbox, you would need to embed a matplotlib graph within a separate GUI framework. To do this, decide on the GUI framework you want to use (qt, wx, gtk, or tkinter), and a textbox widget from the gui framework, and then add the plot from matplotlib. This isn't difficult and there are lots of available examples, generally best found for each specific framework you're interested in.
There might also be other pure matplotlib approaches that could work for you, such as using a matplotlib slider widget, or you could directly capture keyboard events, but without knowing exactly what you're going to for, it's hard to say.

Matplotlib/Python: customize a Zoom-in at show call

I have a candlestick chart that is dinamically created for different lengths and stocks. The chart is created first (the creation of the chart is contained in a function "createChart") and not shown until the moment the user presses on the button "Show Chart", that will hence call the instruction .show() and display the plot previously created. When the user clicks on the button he gets the following result:
However, what I would like to get is a chart that is already zoomed-in, let's say, on the last 5% of data. So what I would like to get is when the user presses on the button "Show Chart" the plot (that has been already fully created into the "createChart" function) should zoom on the last couple of months, so Nov 2012 - Dec 2012, but so allowing the user to scroll back/forward:
Hence my question is: to make the chart more user-friendly and zoom-in directly on the last observations (that in finance are the most relevant), but still giving the user the possibility of slide the chart and going back or forward as he wishes, how could I customize the .show() method to get this result?
I propose you to use the navigation toolbar tools; here is an example:
from pylab import *
x=[1,2,2,3,5]
y=[2,3,4,5,6]
fig=figure() # create and store a figure
tb=fig.canvas.toolbar # get the toolbar of the figure
ax=fig.add_subplot(1,1,1) # add axes to the figure
ax.plot(x,y) # plot
tb.push_current() # save the current zoom in the view stack
ax.set_xlim([1,3]) # change xlims
ax.set_ylim([2,5]) # change ylims
tb.push_current() # save the new position in the view stack
show() # show the figure
What about xlim((from, to)) and ylim((from, to))?
It limits only the view, not what data is actually plotted. You might have to pay attention to the case where you have a whole lot of data, then the plot() or show() command takes ages to load.

How to graphically edit the graph of a mathematical function (with python)?

Is there already a python package allowing to graphically edit the graph of a function?
Chaco is designed to be very interactive, and is significantly more so than matplotlib. For example, the user can use the mouse to drag the legend to different places on a plot, or lasso data, or move a point around on one plot and change the results in another, or change the color of a plot by clicking on a swatch, etc.

Categories

Resources