473,226 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

Embedding Matplotlib in wxpython wx.Panel problem


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

Any help would be appreciated!


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.numerix import arange, sin, cos, pi
import matplotlib

from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from matplotlib.figure import Figure

class App(wx.App):

def OnInit(self):
self.frame = MainFrame("Autoplotter", (50,60), (700,700))

return True

class MainFrame(wx.Frame):

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

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

bPanel = ButtonPanel(self, 100,500, (200,100)) # button

sizer = wx.BoxSizer(wx.VERTICAL)



class ButtonPanel(wx.Panel):

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

pos = (xPos, yPos)
wx.Panel.__init__(self, Parent, -1, pos, style =
wx.RAISED_BORDER, size = insize)

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

class NoRepaintCanvas(FigureCanvasWxAgg):
"""We subclass FigureCanvasWxAgg, 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):
FigureCanvasWxAgg.__init__(self, *args, **kwargs)
self._drawn = 0

def _onPaint(self, evt):
Called when wxPaintEvt is generated
if not self._isRealized:

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

class PlotPanel(wx.Panel):

def __init__(self, parent, id = -1, color = None,\
dpi = None, style = wx.NO_FULL_REPAINT_ON_RESIZE,

wx.Panel.__init__(self, parent, id = id, style = style,

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

self.Bind(wx.EVT_IDLE, self._onIdle)
self.Bind(wx.EVT_SIZE, self._onSize)


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.plot(x,y, '-r')

def _onSize(self, event):
self._resizeflag = True

def _onIdle(self, evt):
if self._resizeflag:
self._resizeflag = False

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.GetClientSize()
if __name__ == "__main__":

app = App(0)

Apr 25 '07 #1
0 1907

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

Similar topics

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...
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...
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...
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....
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...
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...
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....
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:...
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...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.