Files
Phoenix/demo/PyPlot.py
Edouard Choinière 95cafd1a3f style: Normalise numpy imports with import numpy as np
The convention when importing numpy is to use `import numpy as np`

Fixes: unconventional-import-alias (ICN001)
Ruff rule: https://docs.astral.sh/ruff/rules/unconventional-import-alias/
2025-02-08 16:48:57 +00:00

84 lines
2.4 KiB
Python

import wx
hadImportError = False
try:
import numpy as np
import wx.lib.plot
except ImportError:
hadImportError = True
#############################################################################
# Where's the code???
#
# The wx.lib.plot package comes with its own excellent demo built in, for
# testing purposes, but it serves quite well to demonstrate the code and
# classes within, so we are simply importing and using that code for this
# sample in the wxPython demo. Please load up wx/lib/plot/examples/demo.py
# for a review of the demo code itself.
#############################################################################
#---------------------------------------------------------------------------
class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
wx.Panel.__init__(self, parent, -1)
b = wx.Button(self, -1, "Show the PyPlot sample", (50,50))
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
def OnButton(self, evt):
from wx.lib.plot.examples.demo import PlotDemoMainFrame
win = PlotDemoMainFrame(self, -1, "wx.lib.plot Demo")
win.Show()
#---------------------------------------------------------------------------
def runTest(frame, nb, log):
if not hadImportError:
win = TestPanel(nb, log)
else:
from wx.lib.msgpanel import MessagePanel
win = MessagePanel(nb, """\
This demo requires the numpy module, which could not be imported.
It probably is not installed (it's not part of the standard Python
distribution). See https://pypi.python.org/pypi/numpy for information
about the numpy package.""", 'Sorry', wx.ICON_WARNING)
return win
#----------------------------------------------------------------------
if hadImportError:
overview = ""
else:
overview = """\
<html><body>
<center><h2>PyPlot</h2></center>
This demo illustrates the features of the PyPlot modules, found
in the wx.lib.plot package.
<p>
The demo illustrates several different plot styles (with appropriate
variations on fonts, etc, to show how flexible it is) as well as
provides you with a means to tinker with all the features that
come with the class itself. Be sure to explore the options in the
Plot and Options menus to explore some of the capabilities of this
plotting package.
</body></html>
"""
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])