473,832 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Embedding Matplotlib in wxpython wx.Panel problem

Hi,

I'm trying to create a small GUI program where I can do plots using
Matplotlib. I've been trying to borrow code from the examples at the
matplotlib website, but I can't get it to work.

I want to be able to create a wx.Panel that contains an axis for
plotting. Around it i want other panels containing various settings,
buttons etc. to control the plot. So far I can't even get the program
to actually show a plot in a panel.

Does anyone here have experience in making a wxpython GUI with
matplotlib?

Any help would be appreciated!

Thanks,
Soren

My code shows a frame, and I'm trying to set up two panels.. one with
a plot and one with a button.. The plotpanel is just a little square
in the corner when I run it.. ???

My code is as follows:

import wx
import pylab
from matplotlib.nume rix import arange, sin, cos, pi
import matplotlib

matplotlib.use( 'WXAgg')
from matplotlib.back ends.backend_wx agg import FigureCanvasWxA gg
from matplotlib.back ends.backend_wx import NavigationToolb ar2Wx
from matplotlib.figu re import Figure
matplotlib.inte ractive(False)

class App(wx.App):

def OnInit(self):
self.frame = MainFrame("Auto plotter", (50,60), (700,700))
self.frame.Show ()

return True

class MainFrame(wx.Fr ame):

def __init__(self, title, pos, size):
wx.Frame.__init __(self, None, -1, title, pos, size)

pPanel = PlotPanel(self, -1) # Plot panel

bPanel = ButtonPanel(sel f, 100,500, (200,100)) # button
panel

sizer = wx.BoxSizer(wx. VERTICAL)

sizer.Add(pPane l,0)
sizer.Add(bPane l,0)

self.SetSizer(s izer)

class ButtonPanel(wx. Panel):

def __init__(self, Parent, xPos, yPos, insize):

pos = (xPos, yPos)
wx.Panel.__init __(self, Parent, -1, pos, style =
wx.RAISED_BORDE R, size = insize)

button = wx.Button(self, -1, 'HELLO!!', (10,10), (150,50))

class NoRepaintCanvas (FigureCanvasWx Agg):
"""We subclass FigureCanvasWxA gg, overriding the _onPaint method,
so that
the draw method is only called for the first two paint events.
After that,
the canvas will only be redrawn when it is resized.
"""
def __init__(self, *args, **kwargs):
FigureCanvasWxA gg.__init__(sel f, *args, **kwargs)
self._drawn = 0

def _onPaint(self, evt):
"""
Called when wxPaintEvt is generated
"""
if not self._isRealize d:
self.realize()

if self._drawn < 2:
self.draw(repai nt = False)
self._drawn += 1

self.gui_repain t(drawDC=wx.Pai ntDC(self))
class PlotPanel(wx.Pa nel):

def __init__(self, parent, id = -1, color = None,\
dpi = None, style = wx.NO_FULL_REPA INT_ON_RESIZE,
**kwargs):

wx.Panel.__init __(self, parent, id = id, style = style,
**kwargs)

self.figure = Figure(None, dpi)
self.canvas = NoRepaintCanvas (self, -1, self.figure)
self._resizefla g = True

self.Bind(wx.EV T_IDLE, self._onIdle)
self.Bind(wx.EV T_SIZE, self._onSize)

self._SetSize()

def draw(self): # just draw something!
if not hasattr(self, 'subplot'):
self.subplot = self.figure.add _subplot(111)
theta = arange(0, 45*2*pi, 0.02)
rad = (0.8*theta/(2*pi)+1)
r = rad*(8 + sin(theta*7+rad/1.8))
x = r*cos(theta)
y = r*sin(theta)
#Now draw it
self.subplot.pl ot(x,y, '-r')

def _onSize(self, event):
self._resizefla g = True

def _onIdle(self, evt):
if self._resizefla g:
self._resizefla g = False
self._SetSize()
self.draw()

def _SetSize(self, pixels = None):
"""
This method can be called to force the Plot to be a desired
size, which defaults to
the ClientSize of the panel
"""
if not pixels:
pixels = self.GetClientS ize()
self.canvas.Set Size(pixels)
self.figure.set _figsize_inches (pixels[0]/
self.figure.get _dpi(),
pixels[1]/self.figure.get _dpi())
if __name__ == "__main__":

app = App(0)
app.MainLoop()

Apr 25 '07 #1
0 1942

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2180
by: Piet | last post by:
Hello wxPythoneers. I have a problem with a dialog box derived from wxFrame which has a wxComboBox as main element. Depending on the entry selected from the ComboBox, the dialog box will be populated with a number of controls. This works fine for the first selection of a combobox item, but subsequent selections from the combobox cause problems. This is because the event function for the combobox populates the sizer for the window with...
0
1277
by: Oh Kyu Yoon | last post by:
Hi! I am making a small program using boa constructor. This program converts fine into an exe file using py2exe. Then, I embedded a figure canvas from matplotlib in a wxpython panel. I followed the instructions given by py2exe wiki about matplotlib and tried to convert to an exe file. It first said several modules were missing. I realized that those were modules that matplotlib or Numeric will try to import and then provide the codes on...
2
3186
by: dr_tyson | last post by:
I am trying to embed images into a wxPython app (created using Boa Constructor), but have not been able to do so. I know how to embed plots, but images seem to be a problem. I've tried using code analogous to the example given at the Matplotlib website to no avail. If anybody has been successful at this could you please post some sample code? That would be greatly appreciated. Thanks! Randy
9
5561
by: zxo102 | last post by:
Hi everyone, I am using a python socket server to collect data from a socket client and then control a image location ( wxpython) with the data, i.e. moving the image around in the wxpython frame. But the "app.MainLoop()" in wxpython looks like conflicting with the "while 1:" in socket server. After I commented the "app.MainLoop()", everything is working except two things: 1. if I click anywhere on the screen with the mouse, the image is...
3
2577
by: Sam | last post by:
Hello, I'm currently creating a GUI, which consists of a main frame that contains a menu bar,a toolbar and an empty panel, let's call it main_panel. Ideally, I'd like the following functionality: upon choosing an item from the menu bar, a particular graph will be displayed inside main_panel. Now I've taken a look at the 'embedding_in_wx' example files that come
9
4457
by: Tyler | last post by:
Hello All: I am currently working on a project to create an FEM model for school. I was thinking about using wxPython to gather the 12 input variables from the user, then, after pressing the "Run" button, the GUI would close, and the 12 input variables would then be available for the rest of the program. So far, what I have been able to do is mostly a reverse engineering job to get the frame to look right and return the text variable...
0
3405
by: Soren | last post by:
Hi, I've been trying to embed matplotlib in wxpython. I want to be able to put a figure (axes) in a wx.Panel and place it somewhere in my GUI. The GUI should have other panels with buttons etc. that can control the output on the figure. I've been looking at the examples from the matplotlib website, but can't seem to get it to work.. Does anyone here have experience in embedding matplotlib in wxpython?
2
3535
by: John | last post by:
I'm trying to install matplotlib and currently getting the below error. I searched the group and google and couldn't find anything similar... Any ideas? Thanks in advance! src/ft2font.cpp: In member function 'Py::Object Glyph::get_path(FT_FaceRec_* const&)': src/ft2font.cpp:441: error: 'FT_CURVE_TAG_CUBIC' was not declared in this scope
4
9697
by: John Henry | last post by:
Has anybody been able to create an exe of their python applications involving matplotlib using pyinstall (ver 1.3)? I am getting a: RuntimeError: Could not find the matplotlib data files when I attempt to run the exe created. In searching the web, it appears this is an issue when others tried to use py2exe as well. Unfortunately, the few hits I saw doesn't include enough details to inspire me as to what I should be doing in my
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10781
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10541
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10212
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5624
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5789
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4421
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3078
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.