File: plotcanvas.py

package info (click to toggle)
wxpython4.0 4.2.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 218,584 kB
  • sloc: cpp: 962,669; python: 231,226; ansic: 170,755; makefile: 51,757; sh: 9,342; perl: 1,564; javascript: 584; php: 326; xml: 200
file content (41 lines) | stat: -rw-r--r-- 1,349 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# A PlotCanvas is a Subclass of a wx.Panel which holds two scrollbars and the
# actual plotting zoom canvas (self.canvas). It allows for simple general
# plotting of data with zo om, labels, and automatic axis scaling.

import wx
import wx.lib.plot as plot


class MyFrame(wx.Frame):

    def __init__(self, parent, title):
        super().__init__(parent, title=title, size=(600, 400))

        # Create a PlotCanvas instance
        self.plot_canvas = plot.PlotCanvas(self)

        # Define some sample data
        data1 = [(1, 2), (2, 5), (3, 4), (4, 7), (5, 6)]
        data2 = [(1, 1), (2, 3), (3, 6), (4, 5), (5, 8)]

        # Create PolyLine objects for the data
        line1 = plot.PolyLine(data1, colour='blue', width=2, legend='Line 1')
        line2 = plot.PolyLine(data2, colour='red', width=2, legend='Line 2')

        # Create a PlotGraphics object to hold the lines and define labels
        graphics = plot.PlotGraphics([line1, line2],
                                     "Sample Plot",
                                     "X-axis Label",
                                     "Y-axis Label")

        # Draw the plot on the canvas
        self.plot_canvas.Draw(graphics)

        self.Centre()
        self.Show()


if __name__ == '__main__':
    app = wx.App()
    frame = MyFrame(None, "PlotCanvas Demo")
    app.MainLoop()