Merge pull request #2794 from jmoraleda/plotcanvas-sample
Some checks failed
ci-build / build-source-dist (push) Has been cancelled
ci-build / Build wxPython documentation (push) Has been cancelled
ci-build / build-wheels (arm64, macos-14, 3.10) (push) Has been cancelled
ci-build / build-wheels (arm64, macos-14, 3.11) (push) Has been cancelled
ci-build / build-wheels (arm64, macos-14, 3.12) (push) Has been cancelled
ci-build / build-wheels (arm64, macos-14, 3.13) (push) Has been cancelled
ci-build / build-wheels (arm64, macos-14, 3.14) (push) Has been cancelled
ci-build / build-wheels (arm64, macos-14, 3.9) (push) Has been cancelled
ci-build / build-wheels (arm64, windows-11-arm, 3.11) (push) Has been cancelled
ci-build / build-wheels (arm64, windows-11-arm, 3.12) (push) Has been cancelled
ci-build / build-wheels (arm64, windows-11-arm, 3.13) (push) Has been cancelled
ci-build / build-wheels (arm64, windows-11-arm, 3.14) (push) Has been cancelled
ci-build / build-wheels (x64, macos-13, 3.10) (push) Has been cancelled
ci-build / build-wheels (x64, macos-13, 3.11) (push) Has been cancelled
ci-build / build-wheels (x64, macos-13, 3.12) (push) Has been cancelled
ci-build / build-wheels (x64, macos-13, 3.13) (push) Has been cancelled
ci-build / build-wheels (x64, macos-13, 3.14) (push) Has been cancelled
ci-build / build-wheels (x64, macos-13, 3.9) (push) Has been cancelled
ci-build / build-wheels (x64, ubuntu-22.04, 3.10) (push) Has been cancelled
ci-build / build-wheels (x64, ubuntu-22.04, 3.11) (push) Has been cancelled
ci-build / build-wheels (x64, ubuntu-22.04, 3.12) (push) Has been cancelled
ci-build / build-wheels (x64, ubuntu-22.04, 3.13) (push) Has been cancelled
ci-build / build-wheels (x64, ubuntu-22.04, 3.14) (push) Has been cancelled
ci-build / build-wheels (x64, ubuntu-22.04, 3.9) (push) Has been cancelled
ci-build / build-wheels (x64, windows-2022, 3.10) (push) Has been cancelled
ci-build / build-wheels (x64, windows-2022, 3.11) (push) Has been cancelled
ci-build / build-wheels (x64, windows-2022, 3.12) (push) Has been cancelled
ci-build / build-wheels (x64, windows-2022, 3.13) (push) Has been cancelled
ci-build / build-wheels (x64, windows-2022, 3.14) (push) Has been cancelled
ci-build / build-wheels (x64, windows-2022, 3.9) (push) Has been cancelled
ci-build / build-wheels (x86, windows-2022, 3.10) (push) Has been cancelled
ci-build / build-wheels (x86, windows-2022, 3.11) (push) Has been cancelled
ci-build / build-wheels (x86, windows-2022, 3.12) (push) Has been cancelled
ci-build / build-wheels (x86, windows-2022, 3.13) (push) Has been cancelled
ci-build / build-wheels (x86, windows-2022, 3.14) (push) Has been cancelled
ci-build / build-wheels (x86, windows-2022, 3.9) (push) Has been cancelled
ci-build / Publish Python distribution to PyPI (push) Has been cancelled
ci-build / Create GitHub Release and upload source (push) Has been cancelled
ci-build / Upload wheels to snapshot-builds on wxpython.org (push) Has been cancelled

Add sample of PlotCanvas usage
This commit is contained in:
Scott Talbert
2025-10-23 14:46:20 -04:00
committed by GitHub

View File

@@ -0,0 +1,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()