# Plotting functions import matplotlib.pyplot as plt # Needed at the top of your code to bring in the plotting functions def plotData(xData,yData1,yData2, legend1 ,legend2, xLabel, yLabel, title): """Displays a plot of two yData values over the given common xData. xData = the common x-axis points the yData corresponds to. yData1, yData2 = lists of y-axis data that corresponds with the given xData values. legend1, legend2 = the legend text for the respective yData xLabel, yLabel = the labels for the axes in the plot. title = the title of the plot """ # Prey use circles connected by solid line. plot1 = plt.plot(xData, yData1, 'o-' ) # Predators use squares connected by dotted line. plot2 = plt.plot(txData, yData2, 's:' ) # Place legend box in "best" location. plt.legend( (plot1, plot2), (legend1, legend2), 'best') plt.xlabel(xLabel) plt.ylabel(yLabel) plt.title(title) plt.show() def makeTimePlot(data, legendSymbols, tLabel, yLabel, title): """ Make a plot of a list of tuples of at least two elements where all elements in the tuples are plotted against the first value in the tuple data = list of tuples (time, y1, y2, y3, ...) legendSymbols = list of tuples (legend1, symbol1) corresponding to the y-data. symbolx="" means line only, no symbols tLabel, yLabel = the labels for the time and y axis respectively title = the top title for the plot Returns the plt.Figure object created. --show() MUST be called after this function to display the plots!-- """ fig = plt.figure() legSyms = zip(*legendSymbols) fax = fig.add_subplot(111) results = zip(*data) # transpose the data plots = [] for i in range(1, len(data[0])) : plots.append(fax.plot(results[0], results[i], (legSyms[1])[i-1]+'-')) fax.legend(plots, legSyms[0], 'best') # legend box placed in "best" location fax.set_xlabel(tLabel) fax.set_ylabel(yLabel) fax.set_title(title) return fig def makeXYPlot(data, legendSymbols, xLabel, yLabel, title): """ Make a plot of multiple lists of x-y tuples data = list of lists of tuples (x, y) legendSymbols = list of tuples (legend1, symbol1) corresponding to the xy-data. symbolx="" means line only, no symbols xLabel, yLabel = the labels for the x and y axis respectively title = the top title for the plot Returns the plt.Figure object created. --show() MUST be called after this function to display the plots!-- """ fig = plt.figure() legSyms = zip(*legendSymbols) fax = fig.add_subplot(111) plots = [] for i in range(len(data)) : results = zip(*data[i]) # transpose the data plots.append(fax.plot(results[0], results[1], (legSyms[1])[i]+'-')) fax.legend(plots, legSyms[0], 'best') # legend box placed in "best" location fax.set_xlabel(xLabel) fax.set_ylabel(yLabel) fax.set_title(title) return fig def show(): """ Display all the pending, invisible plot windows.""" plt.show() def reset(): """ Close all the pending, invisible plot windows.""" plt.close('all')