def PlotNetwork(numOfNodes): #First plot----------------------------------------------------- tempList = [] plt=SimPlot() plt.root.title("The plot") objects = [] for i in range(numOfNodes): tempList.append([G.NodesLocations[i][0],G.NodesLocations[i][1]]) dots = plt.makeSymbols(tempList,color="green",size=2,marker='circle',windowsize=(1000,600)) objects.append(dots) for i in range(numOfNodes): for j in range(i, numOfNodes): src = [G.NodesLocations[i][0],G.NodesLocations[i][1]] dst = [G.NodesLocations[j][0],G.NodesLocations[j][1]] #objects.append(plt.makeLine([src,dst],splinesteps=20,color="blue",width=2)) obj=plt.makeGraphObjects(objects) frame=Frame(plt.root) graph=plt.makeGraphBase(frame,1000,600, title="Network") graph.pack() graph.draw(obj) frame.pack() #Second plot----------------------------------------------------- #Need to create a new root (Tk()) for every new plot #We use the same 'plt' object root1 = Tk() root1.title = "Panel 2" line = plt.makeLine([[0,0],[1,1],[2,4],[3,9]]) obj2 = plt.makeGraphObjects([line]) #Need to create a new frame and graph for our new root frame2=Frame(root1) graph2=plt.makeGraphBase(frame2,1000,600, title="Network") graph2.pack() graph2.draw(obj2) frame2.pack() #This must be at the end plt.mainloop()
print "Normalizing data..." normalizedData = {} for lang in Parameters.languages: data = [] lastDatum = None for datum in lang.population.bufferMon: if lastDatum and datum[0] > lastDatum[0]: data.append(lastDatum) lastDatum = datum normalizedData[lang] = data colors = iter(["red", "green", "blue", "black", "yellow", "cyan", "magenta"]) plt = SimPlot() # step 1 plt.root.title("Language Population Levels") # step 3 lines = [] print "Language Colors:" for lang in Parameters.languages: color = colors.next() print "\t%s: %s" % (lang, color) lines.append(plt.makeLine(normalizedData[lang], color=color)) # lines.append(plt.makeLine(lang.population.bufferMon, color=color)) obj = plt.makeGraphObjects(lines) # step 5 frame = Frame(plt.root) # step 6 graph = plt.makeGraphBase(frame, 640, 480, title="Population Levels", xtitle="Time", ytitle="Speakers") # step 7 graph.pack() # step 8 graph.draw(obj) # step 9 frame.pack() # step 10 # graph.postscr() plt.mainloop() # step 12
edge = [ind, rod] self.EdgeList.append(edge) self.EdgeList = dict(self.EdgeList) def channelOn(self, chn): self.EdgeList[chn].color = v.color.red def channelOff(self, chn): self.EdgeList[chn].color = v.color.green initialize() Net = Network() if G.vis_on: V = Vis() for N in Net.Nodes: N.initCounterparts() N.activate() simulate(until=G.max_time) print 'Sim Finished, Visualising graphs...' if not G.vis_on: plt = SimPlot() plt2 = SimPlot() plt2.plotLine(Net.waitQMon) plt.plotLine(Net.activeQMon) plt.mainloop() #nx.draw(Net.graph_plan) #plt.show()
self.EdgeList[chn].color=v.color.red def channelOff(self,chn): self.EdgeList[chn].color=v.color.green initialize() Net = Network() if G.vis_on: V = Vis() for N in Net.Nodes: N.initCounterparts() N.activate() simulate(until=G.max_time) print 'Sim Finished, Visualising graphs...' if not G.vis_on: plt = SimPlot() plt2 = SimPlot() plt2.plotLine(Net.waitQMon) plt.plotLine(Net.activeQMon) plt.mainloop() #nx.draw(Net.graph_plan) #plt.show()
def MyXYPlot(X, Y): Z = zip(X, Y) plt = SimPlot() plt.plotLine(Z) plt.mainloop()
# AdvancedAPI.py from SimPy.SimPlot import * plt = SimPlot() # step 1 plt.root.title("Advanced API example") # step 3 line = plt.makeLine([[0, 42], [1, 1], [4, 16]]) # step 4 bar = plt.makeBars([[0, 42], [1, 1], [4, 16]], color='blue') # step 4 sym = plt.makeSymbols([[1, 1]], marker="triangle", size=3, fillcolor="red") # step 4 obj = plt.makeGraphObjects([line, bar, sym]) # step 5 frame = Frame(plt.root) # step 6 graph = plt.makeGraphBase(frame, 500, 300, title="Line and bars") # step 7 graph.pack() # step 8 graph.draw(obj) # step 9 frame.pack() # step 10 graph.postscr() # step 11 plt.mainloop() # step 12
# Experiment data ------------------------- maxTime = 400.0 # minutes counter = Resource(1, name="Clerk", monitored=True) # Model ----------------------------------- def model(SEED=393939): # 3 seed(SEED) initialize() source = Source() activate( source, # 4 source.generate(number=20, rate=0.1), at=0.0) simulate(until=maxTime) # 5 # Experiment ----------------------------------- model() plt = SimPlot() # 6 plt.plotStep( counter.waitMon, # 7 color="red", width=2) # 8 plt.mainloop() # 9
maxTime = 400.0 # minutes counter = Resource(1, name="Clerk") Mon = Monitor('Time in the Bank') # 4 N = 0 # Model ---------------------------------- def model(SEED=393939): seed(SEED) initialize() source = Source() activate(source, source.generate(number=20, rate=0.1), at=0.0) simulate(until=maxTime) # Experiment ---------------------------------- model() Histo = Mon.histogram(low=0.0, high=200.0, nbins=20) # 5 plt = SimPlot() # 6 plt.plotHistogram( Histo, xlab='Time (min)', # 7 title="Time in the Bank", color="red", width=2) plt.mainloop() # 8