To begin with, we'll allow users to pick a number (e.g. We will have a simple user menu which will allow the use to select the column they want to chart. Create a third file, graphing.py, that contains a function that creates the scatter plot given the x and y values.Create a file, such as data_storage.py, that contains functions to read the iris.csv data file.Use the file () to contain the user menu.I would recommend tackling this project this way: Also via the menu, tell us the name of the file they would like to create to contain the final plot image.Via a user menu, tell us the column they would like to plot in the y axis.Create a scatter plot where the x axis is the species and the y axis is one of the other columns.When you get to the point of asking the user over and over to create new graphs and new files for them, you may run into a problem: pyplot by default will add new data points to the existing graph instead of creating new graphs. It can't do that if we plot strings, because it doesn't know how to get the maximum value of a list of strings. Pyplot can do this if the values we're plotting are numbers. It automatically calculated the size of each axis based on the maximum value plotted. Notice that we never told pyplot how large the axes should be. Otherwise you might end up with some points that have an x position but no y position! Defining the axes Therefore, x_data and y_data must be the same length. Then it repeats for the second value, and then the third. When creating a scatter plot, pyplot takes the first value of x_data and the first value of y_data and draws a small circle in their designated location. We've defined x_data and y_data, two list variables. Tell pyplot to save the output generated to a file.Tell pyplot to use that data to draw a scatter plot.Other than importing pyplot, what we've done is: That is the image file that contains the output of pyplot. If you type that out and run it, you'll see that a new file appears in your project called graph.png. From matplotlib import pyplot x_data = y_data = pyplot.
0 Comments
Leave a Reply. |