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.
Related
I am trying to display spectrograms in a Flask application. I use matplotlib for creating the spectrograms and mpld3 for displaying them in an HTML file with the default toolbar.
The problem is that I am not able to zoom into the same region for each spectrogram at the same time.
This is a screenshot of default figure
This is another screenshot that I took after zooming in a little bit on a left top one.
As you can see, all of the y-axes have been changed with the same scale as the left top ones. However, the x-axes of the right top, the left bottom, and the right bottom haven't been changed at all. So what I want to do is to compare those guys with the same scale.
Does anyone have any suggestion such as a better idea to make it possible or maybe the solution for the problem?
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.
I'm now embedding matplotlib plot in a simple GUI. During the customization of the plot, I found some displaying issues occurred when I added tool bar under the plot using NavigationToolbar2TkAgg. Now I want to disable displaying coordinate at right side of the bottom of plot when mouse moves around the plot, if we add tool bars at the left side of the bottom. Any idea about this?
Thanks in advance.
Update:
For a figure simply drawn by plt.plot(x,y), the coordinates are displayed at left side of the bottom along with mouse moving as tool bars (like "home", "zoom" etc.) are listed at the top by default. It will be much clearer to view the screen shot at google drive here and I highlighted the coordinates in yellow, which one can find at the bottom left of the image. Thanks GWW and jgysland for reminding me.
You want the opposite of matplotlib values under cursor, but the solution is the same, you need to over-write the format_coord attribute on the Axes object.
ax.format_coord = lambda x, y: ''
should do the trick where ax is a reference to the axes object you care about.
Another option is to sub-class NavigationToolbar2TkAgg and make the set_message function a no-op
class my_toolbar(NavigationToolbar2TkAgg):
def set_message(self, msg):
pass
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
I have a 2 part question:
what is the best method for plotting data in Python? I only need to plot data in 2d.
I have a canvas GUI that I built using Tkinter's canvas function. It draws an 8x8 grid of rectangles and also has some code to allow you to scroll the window. (I've attached a picture).
Is it possible to include a plot in the same window as this canvas object? I need to be able to display plotted data and hopefully add buttons to my GUI that will allow me to update the plot during the run of the GUI.
Thanks in advance!
Matplotlib is the de-facto way to plot data with Python. It's really wonderful. It can also be embedded in Tk.