The wxPython GUI toolkit makes a very nice plotting component/widget available. You can select line or marker plotting, or a combination of both. All you have to supply is a list of x,y point tuples. Other features include zooming and printing.
Using wxPython for Plotting
# using wxPython for plotting
# tested with Python24, wxPython26 and wxPython28 vegaseat 19apr2007
import wx
import wx.lib.plot as plot
class MyFrame(wx.Frame):
def __init__(self):
self.frame1 = wx.Frame(None, title="wx.lib.plot", id=-1, size=(410, 340))
self.panel1 = wx.Panel(self.frame1)
self.panel1.SetBackgroundColour("yellow")
# mild difference between wxPython26 and wxPython28
if wx.VERSION[1] < 7:
plotter = plot.PlotCanvas(self.panel1, size=(400, 300))
else:
plotter = plot.PlotCanvas(self.panel1)
plotter.SetInitialSize(size=(400, 300))
# enable the zoom feature (drag a box around area of interest)
plotter.SetEnableZoom(True)
# list of (x,y) data point tuples
data = [(1,2), (2,3), (3,5), (4,6), (5,8), (6,8), (12,10), (13,4)]
# draw points as a line
line = plot.PolyLine(data, colour='red', width=1)
# also draw markers, default colour is black and size is 2
# other shapes 'circle', 'cross', 'square', 'dot', 'plus'
marker = plot.PolyMarker(data, marker='triangle')
# set up text, axis and draw
gc = plot.PlotGraphics([line, marker], 'Line/Marker Graph', 'x axis', 'y axis')
plotter.Draw(gc, xAxis=(0,15), yAxis=(0,15))
self.frame1.Show(True)
app = wx.PySimpleApp()
f = MyFrame()
app.MainLoop()
aernie 0 Newbie Poster
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
aernie 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.