Hi all !
I created a little wxpython app with some matplotlib figures inside. Here is my figure:
The number 1 is my zoom window, and i would like to obtain the xmin, xmax, ymin, ymax of the number 2. Do you know how to do that ?
At the end, I would like to have my zoom windows with the y is the same as the number 2.
I’m not sure what you want to accomplish exactly, but this example contains some code about interacting with an embedded matplotlib canvas:
https://github.com/wxGlade/wxGlade/tree/master/examples/matplotlib3
The most interesting code for you is probably init_events()
in matplotlib_example.py
Regards,
Dietmar
P.S.: Posting the same question on multiple lists / forums is not a good idea.
Actually, I am programming a function to zoom only on y or x.
I already have a function to zoom.
When I zoom, I create first rectangle area with my cursor and I will zoom on this area.
Here is the part of my code to create the rectangle area:
zdc = wx.ClientDC(self.canvas)
zdc.SetLogicalFunction(wx.XOR)
zdc.SetBrush(wx.TRANSPARENT_BRUSH)
zdc.SetPen(wx.Pen('White', 2, wx.SOLID))
zdc.ResetBoundingBox()
if not is_wxPhoenix:
zdc.BeginDrawing()
# erase previous box
if self.rbbox is not None:
zdc.DrawRectangle(*self.rbbox)
`self.rbbox = (x0, y0, width, height)`
zdc.DrawRectangle(*self.rbbox)
if not is_wxPhoenix:
zdc.EndDrawing()
This is the line self.rbbox = (x0, y0, width, height)
which contains the coordinates. In zoom on x mode, I would like to get back the values of my y0 and ymax to create a rectangular area on my plot. Is it more clear ?
I have seen that I can get back height with self.canvas.figure.bbox.height
.
And sorry again about multiple forums, I have first created my post in the google group and have seen after that that this forum replaced the google group, that’s why I published on this group after. I thought that the google group was not used anymore.
This question is maybe a bit too special for this forum as that anyone had it himself before.
I would suggest that you either ask on the matplotlib-users list or attach fully runable code here such that people can execute and try it. Nobody will re-build your problem to solve it.
Usually, for such problems I have a look in the debugger or built-in shell.
E.g. you’ve found canvas.figure.bbox.height
already. I’ve just tried the shell in matplotlib_example3
and found canvas.figure.axes[0].bbox.corners()
. Maybe this is what you’re looking for.
Regards,
Dietmar
Sorry How did you find this function ? What is the shell in matplotlib_example3
?
The example mentioned above https://github.com/wxGlade/wxGlade/tree/master/examples/matplotlib3 has a wx.py.shell.Shell
:
Usually, a debugger offers a bit more functionality, e.g. introspection into list elements.
See here for a screenshot of a wxPython application running in the Wing IDE debugger:
http://wxglade.sourceforge.net/docs/source_code.html#hints-and-tips
Ok Thanks. I am using Spyder, is there a equivalent function ?
And for canvas.figure.axes[0].bbox.corners()
, I saw that is it an array with four coordinates. ShouldI use them directly like that :
coordinates = canvas.figure.axes[0].bbox.corners()
self.rbbox = (x0, coordinates[0][1], width, coordinates[1][1]) ?
I tried that but it’s not good.
I can just repeat myself: the question is too special to expect a 100% working reply, except if you post a running code sample.
I don’t know about Spyder’s debugger.
I don’t use IDEs that install themselves into the target system. For me that’s a no-go.
Regards,
Dietmar
Ok, you can clone this repository:
And launch USB_Energetics_Spy_v4.py, push the button, select the file 200305.txt, and in one of the windows, select in Options Zoom on X, and after it will create a weird box when you will zoom. To change this box, this is in the file basepanel.py, the line 606, self.rbbox = (x0, limits[0][1], width, height)
.
Hope it will work, I haven’t checked if when I cloned it on another computer it will work directly or not. I am on windows.
Much easier with the code available for running in the debugger, even though it’s not quite a minimum sample…
The solution was to check self.rbbox
when doing a ‘normal’ drag with the mouse pointer on an axis.
It’s just a mismatch of coordinate system: matplotlib has y0 at bottom, wx at top.
You need to figure out the details, but this should get you started:
self.rbbox = (x0, self.GetSize()[1] - int(round(limits[1][1])), width, height)
Regards,
Dietmar