Make a label / annotation appear, when hovering over an area (rectangle) - python

As you can see the question above, I was wondering, if it is possible to popup a label, when I hover on a rectangle-area.
I found this solution which helped me for popping up a label over a point.
But is it possible to popup a label, when the user hovers somewhere over an area?
On my plot, I'm using this code example for adding rectangles:
http://matthiaseisen.com/pp/patterns/p0203/
Let's use this as example:
(source: matthiaseisen.com)
When the user hovers (everywhere) over the blue area, a popup "You are hovering over the blue area" should appear.
Is this even possible in matplotlib? I can't find any solution for this problem.

Matplotlib by itself isn't going to give you this functionality. Bokeh (link), another python library, is what you want. Here is an example with the hovertool feature, which is what you're looking for. You can even export the image as html so you can put it on a website or blog.

Related

How can I click elements inside Dash Tooltip?

I have a scatter plot graph and a dcc.Tooltip which shows over points on hover, similar to the examples here.
I want to add some interactive components within the tooltip, e.g. a button, but I cannot click anything within the tooltip. I can't even highlight text. It seems I just click through the tooltip and interact with the graph behind it.
Is there a way to interact with components inside a dcc.Tooltip?

How to create a user created textbox on top of matplotlib figure?

BackGround
I'm making this software right plot data as boxplots and scatter plots. To make the graph more informative and clear I wanted the user to be able to drag-create a textbox on top of the figure if they wanted to add notes. This way when people share the figure it can be explained through these notes.
Current Approach and Problem
I have used annotate function to create a textbox in the upper right corner of the screen to tell the user how many data points have been used, but there are of few problems with this approach.
This is the code I used to create a text box to tell the user how many data pts there are.
self.axes.text(.98, .98, 'Number of Data Points: {}'.format(len(self.cleanedY)),
verticalalignment='top', horizontalalignment='right',
transform=self.axes.transAxes,
color='black', fontsize=9.5)
Extensive input that would have to be asked of the user. This includes the position coordinates, the actual text box, type of alignment.
The only way I know how to collect this info would be to create a Qdialog window prompting for all these inputs, which would be too cumbersome.
User doesn't have much control over being able to freely position the textbox and would have to know exact decimals to position the text box on the figure.
This is incredibly inefficient and inflexible. I want a way for the user to EASILY create these notes on the plot figure.
TLDR: Is there any way to develop a simple drag and create textbox option on a plot figure?
I'm not sure if this is what your looking for, but i found this similar example online. It doesn't allow for user to create a textbox, but adds annotations to the figure and allows you to move them around.
here's the link
http://scipy-cookbook.readthedocs.io/items/Matplotlib_Drag_n_Drop_Text_Example.html

PyQtGraph : how to change size (height and width) of graph in a ScrollArea

I'm trying to plot graph in a scroll area but I've no idea how to change the size of my graphs. Here is an example of what I have:
As you can see, in my ScrollArea (in Red) which as the size I want, I have a graph (well, in reallity I have more graphs and I want to see more then one (at least two) in this area).
So, I want the height of my graph (A) to be smaller and the width of my graph (B) to be expanding. Somine can help me ?
Thanks for your help !
It looks like your plot is inside a layout with the "Hide EMG" button. The widget holding that layout must be resized to fit the scroll area. You'll need to provide a code sample if you want more help than that..
Also consider using pg.MultiPlotWidget, which already provides similar functionality.
Adding to Lukes comment: A PlotWidget, which is probably what we see there, is a QGraphicsView, which is a QWidget. This is layed out using Qt. I'd recommend you to play a bit with Qt Designer to get an intuition on how the layouting works.
Another resource would be: https://doc.qt.io/qt-5/layout.html
For your explicit problem, if you do not want to get into Qt layouting, you could use QWidget.setMinimumHeight and QWidget.setMaximumHeight to confine the widget vertically. For the horizontal part, that totally depends on what you are doing there. If that was a grid layout, I'd refer to e.g.: Expanding only one column in a QGridLayout

Matplotlib zooming work in conjunction with wxPython ScrolledWindow

I've got a Matplotlib canvas (FigureCanvasWxAgg) that I'm displaying inside of a wx.ScrolledWindow. The problem is that I'd like to have the default zooming and panning functionality of Matplotlib work in conjunction with the ScrolledWindow, so that when the user zooms the image within the canvas, the ScrolledWindow should become larger to accommodate for the zooming (scrollbars become smaller). Similarly for panning, I'd like the default matplotlib panning tool to work in conjunction with our ScrolledWindow, so that when the user pans the image on the canvas, the ScrolledWindow's scrollbars should move accordingly.
I've been searching for a while now and have not seen anyone even mention if this is possible. Could anyone point me in the right direction?
Thank you for any help/tips.
The problem is that the default Zoom and Pan don't resize the figure, they just change the limits and redraw the plot.
What you want is the Zoom to resize (keeping the same limits) and the Pan to work as in a normal Scrolled window. I have never tried this, fig.set_size_inches(w,h) should do the trick.

Python Visualization: Determining Data Attributes Visually by Mouse Hover and Click

I am rendering very large X,Y,Z scientific datasets in the lateral plane and would like to click on the results to obtain greater textual detail about the area chosen by mouse-click.
So, for example, imagine a scientific dataset which is rendered as a filled contour plot and there is a bright spot. I would like to click on that spot to obtain a link or other textual information.
This would necessitate having another plane that would provide attribute information.
I would be most appreciative for any direction that others have used in similar cases. I expect this problem has been solved previously so I would prefer not reinventing the wheel.
Sounds like you'll need to dive into matplotlib's event handling code. This allows you to take some action when you click on a piece of the plot, or press a key, or whatever. Here are the example programs on the matplotlib site that have to do with event handling.

Categories