CPSC6430 Project 1: Basic plotting in Python with matplotlib.pyplot solution




5/5 - (4 votes)

Data File
The first line of IrisData.txt contains two integers. The first represents how many lines of data
are in the file. The second how many features are associated with each line. Each line after that
contains four floating point values representing the sepal length, sepal width, petal length, and
petal width of a type of iris flower, followed by the name of the iris type: either setosa,
versicolor, or virginica. Values are tab separated.
Python Program
Write a Python program that will print out a two-dimensional plot of any two features for all
three varieties of iris flowers in the plot area of Spyder using the features of
matplotlib.pyplot.Your program should begin by asking for the name of the input file. For
example (blue is user response):
Enter the name of your data file: Irisdata.txt
Then the program should prompt the user for two features to plot. For example, it could say:
You can do a plot of any two features of the Iris Data set
The feature codes are:
0 = sepal length
1 = sepal width
2 = petal length
3 = petal width
Enter feature code for the horizontal axis: 0
Enter feature code for the vertical axis: 1
Once the program does a plot it should ask the user if they want to another plot. For example:
Would you like to do another plot? (y/n) y
If the answer is y, then the user should be prompted for new features to plot on the horizontal
and vertical axes as before and a new plot generated. N should end the program.
Plots should be labelled with a title, axes should be labelled, there should be a legend and all
three varieties should be color coded and have different symbols. An example is shown below.
You are required to submit a project report, including:
• At least 3 plots with different x and y labels combination.
• Briefly discuss which feature combination is the best for classify the iris data
• Full screenshot of your python console.
• A copy of your code
Your report should be named yourlastname_yourfirstname_P1.docx or .doc or .pdf. Your
Python program should be named yourlastname_yourfirstname_P1.py, then zipped together
with your project report and uploaded to Canvas