ich bin relativ neu auf dem Gebiet!
Ich habe mir eine Gui-erzeugt, um feste Funktionen zu plotten. Soll als Grundkonstruktion für ein anderes Programm dienen.
Die Anleitung habe ich hier gefunden
https://www.blog.pythonlibrary.org/2010 ... th-python/
Wenn ich aber die Legende einfügen will, bringt er mir immer diesen Fehler.
Traceback (most recent call last):
File "C:\Phyton\lib\site-packages\wx\lib\plot\plotcanvas.py", line 2154, in OnSize
self._Draw(graphics, xSpec, ySpec)
File "C:\Phyton\lib\site-packages\wx\lib\plot\plotcanvas.py", line 1889, in _Draw
legendTextExt)
File "C:\Phyton\lib\site-packages\wx\lib\plot\plotcanvas.py", line 2240, in _drawLegend
if isinstance(o, PolyMarker) or isinstance(o, BoxPlot):
NameError: global name 'PolyMarker' is not defined
Hier noch mein Quellcode:
Code: Alles auswählen
import wx
import numpy as np
from wx.lib.plot import PolyLine, PlotCanvas, PlotGraphics,PolyMarker
def drawBarGraph(X_Range):
x_start=X_Range[0]
x_end = X_Range[1]
points1=[]
points2=[]
points3=[]
for i in np.arange(x_start,x_end+0.1, 0.1):
points1.append([i, i])
points2.append([i, i ** 2])
points3.append([i, i**3])
line1 = PolyLine(points1, colour="green", legend="linear", width=1)
line2 = PolyLine(points2, colour="red", legend="quadratic", width=1)
line3 = PolyLine(points3, colour="blue", legend="poly", width=1)
return PlotGraphics([line1, line2, line3])
class MyGraph_wx(wx.Frame):
def __init__(self,parent,id,title):
wx.Frame.__init__(self,parent,id,title)
self.parent = parent
self.initialize()
def initialize(self):
#Anlegen der Gitterstruktur
global sizer
sizer = wx.GridBagSizer()
self.canvas=PlotCanvas(self)
sizer.Add(self.canvas, (0, 1), (3, 3), wx.EXPAND)
self.txtXRange=wx.TextCtrl(self,wx.ID_ANY,value=u"X-Range as List[start,end]")
self.Bind(wx.EVT_TEXT_ENTER,self.onPressEnter)
sizer.Add(self.txtXRange,(0,0))
self.Button=wx.Button(self,wx.ID_ANY,label="Show Graph")
self.Button.Bind(wx.EVT_BUTTON,self.onButtonClick)
sizer.Add(self.Button,(2,0))
sizer.AddGrowableCol(1)
sizer.AddGrowableRow(2)
self.SetSizerAndFit(sizer)
self.Show(True)
def onButtonClick(self,event):
X_Range=[]
X_Range=self.txtXRange.Value.split(";")
for i in range(len(X_Range)):
X_Range[i]=float(X_Range[i])
self.canvas.Draw(drawBarGraph(X_Range))
self.canvas.Refresh()
self.canvas.Zoom(((X_Range[0]+X_Range[1])/2,0),(1,1))
def onPressEnter(self,event):
points=[]
points = [(1, 0), (1, 10)]
self.canvas.Draw(PlotGraphics([PolyLine(points,colour="black",legend="Legende",width =10)]))
self.canvas.SetEnableLegend(True)
self.canvas.Refresh()
if __name__ == "__main__":
app = wx.App()
window = MyGraph_wx(None,wx.ID_ANY,"Hoffentlich klappt das")
app.MainLoop()
Danke schon mal im voraus