-
-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples: update matplotlib sample using Wx (and remove deprecated tes…
…t) (#1902)
- Loading branch information
1 parent
953042e
commit f64265b
Showing
5 changed files
with
48 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,55 @@ | ||
"""A simple script to demonstrate matplotlib.""" | ||
|
||
from __future__ import annotations | ||
|
||
import matplotlib | ||
from numpy import arange, pi, sin | ||
|
||
matplotlib.use("WXAgg") | ||
import wx # noqa | ||
from matplotlib.backends.backend_wx import NavigationToolbar2Wx # noqa | ||
from matplotlib.backends.backend_wxagg import ( # noqa | ||
from matplotlib.backends.backend_wxagg import ( | ||
FigureCanvasWxAgg as FigureCanvas, | ||
NavigationToolbar2WxAgg as NavigationToolbar, | ||
) | ||
from matplotlib.figure import Figure # noqa | ||
from matplotlib.figure import Figure | ||
|
||
import numpy as np | ||
|
||
import wx | ||
|
||
|
||
class CanvasFrame(wx.Frame): | ||
def __init__(self): | ||
wx.Frame.__init__(self, None, -1, "CanvasFrame", size=(550, 350)) | ||
color = wx.Colour("WHITE") | ||
self.SetBackgroundColour(color) | ||
super().__init__(None, -1, "CanvasFrame", size=(550, 350)) | ||
|
||
self.figure = Figure() | ||
self.axes = self.figure.add_subplot(111) | ||
t = arange(0.0, 3.0, 0.01) | ||
s = sin(2 * pi * t) | ||
self.axes = self.figure.add_subplot() | ||
t = np.arange(0.0, 3.0, 0.01) | ||
s = np.sin(2 * np.pi * t) | ||
|
||
self.axes.plot(t, s) | ||
self.canvas = FigureCanvas(self, -1, self.figure) | ||
|
||
self.sizer = wx.BoxSizer(wx.VERTICAL) | ||
self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) | ||
self.SetSizerAndFit(self.sizer) | ||
self.add_toolbar() | ||
self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.EXPAND) | ||
self.SetSizer(self.sizer) | ||
self.Fit() | ||
|
||
self.add_toolbar() # comment this out for no toolbar | ||
|
||
def add_toolbar(self): | ||
self.toolbar = NavigationToolbar2Wx(self.canvas) | ||
self.toolbar = NavigationToolbar(self.canvas) | ||
self.toolbar.Realize() | ||
if wx.Platform == "__WXMAC__": | ||
self.SetToolBar(self.toolbar) | ||
else: | ||
tw, th = self.toolbar.GetSize() | ||
fw, fh = self.canvas.GetSize() | ||
self.toolbar.SetSize(wx.Size(fw, th)) | ||
self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND) | ||
# By adding toolbar in sizer, we are able to put it at the bottom | ||
# of the frame - so appearance is closer to GTK version. | ||
self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND) | ||
# update the axes menu on the toolbar | ||
self.toolbar.update() | ||
|
||
def OnPaint(self, event): | ||
self.canvas.draw() | ||
|
||
|
||
class App(wx.App): | ||
def OnInit(self): | ||
"""Create the main window and insert the custom frame""" | ||
"""Create the main window and insert the custom frame.""" | ||
self.Init() | ||
frame = CanvasFrame() | ||
frame.Show(True) | ||
|
||
return True | ||
|
||
|
||
app = App(0) | ||
app.MainLoop() | ||
if __name__ == "__main__": | ||
app = App() | ||
app.MainLoop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters