473,734 Members | 2,806 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

embedding matplotlib in wxpython


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?

I have attached my code.. it makes two panels.. one with a matplotlib
plot, and one with a button.. but the plotpanel is just a small square
in the corner.... !! ..

Any help is appreciated!


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("BioX tas - Autoplotter", (50,60),
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

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:

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,

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

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)


def draw(self):
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

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)

Apr 26 '07 #1
0 3401

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

Similar topics

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...
by: Madhusudan Singh | last post by:
Hi I am still a rookie at python (can do some basic programming with the language), and have been using python gpib and matplotlib to control my instruments and do real time plots. Since I have more than one instrument to control, I was thinking of writing a GUI using Tkinter (looked at Page, but it not have a debian package and I saw quite a few bugs listed - Tkinter seems mature). I have some questions : 1. In using matplotlib (my...
by: Matt Feinstein | last post by:
Hi all-- I'm planning to try to do a completely local install of matplotlib (in Fedora Core 1)-- the system administrator isn't going to stop me-- but he isn't going to cooperate either. I've got the tarballs for python, numeric, numarray, matplotlib, ipython, wxpython and freetype-- which I think covers the various pre-requisites and post-requisites. One semi-obvious question is where to put the freetype library (the system version in...
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
by: Mr. Roboto | last post by:
Folks: I want to embark on a project to add Python (actually, wxPython or PythonWin) to a new Windows app I want to start writing soon. Essentially, I want to take VB6 (or pos Delphi) and construct the app framework/core functionality using one of those languages, then extend the app w/ Python, the same way one can extend the MS Office apps using VBA. The core Python docs provide the fundamental info one needs to get started. But, I've...
by: Soren | last post by:
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.
by: =?ISO-8859-15?Q?J=FCrgen_Kareta?= | last post by:
Hello List, my customer is looking for an application to show some simple 2d graphs based on messured data. I'm consider to use wxpython, matplotlib and py2exe to build and compile this application. Mayby I also like to use WxMPL and inosetup. The target platform is XP embedded. As I don't have XP embedded available, I can't try it out.
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
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
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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,...
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...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
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();...
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...
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
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.