w3resource

Python Scikit-learn: Create a graph to find relationship between the sepal length and width

Python Machine learning Iris Visualization: Exercise-4 with Solution

Write a Python program to create a graph to find relationship between the sepal length and width.

Sample Solution:

Python Code:

import pandas as pd
import matplotlib.pyplot as plt
iris = pd.read_csv("iris.csv")
fig = iris[iris.Species=='Iris-setosa'].plot(kind='scatter',x='SepalLengthCm',y='SepalWidthCm',color='orange', label='Setosa')
iris[iris.Species=='Iris-versicolor'].plot(kind='scatter',x='SepalLengthCm',y='SepalWidthCm',color='blue', label='versicolor',ax=fig)
iris[iris.Species=='Iris-virginica'].plot(kind='scatter',x='SepalLengthCm',y='SepalWidthCm',color='green', label='virginica', ax=fig)
fig.set_xlabel("Sepal Length")
fig.set_ylabel("Sepal Width")
fig.set_title("Sepal Length VS Width")
fig=plt.gcf()
fig.set_size_inches(12,8)
plt.show()

Sample Output:

Python Machine learning Output: Iris Visualization: Exercise-4
 

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to create a Pie plot to get the frequency of the three species of the Iris data.
Next: Write a Python program to create a graph to find relationship between the petal length and width.

What is the difficulty level of this exercise?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://198.211.115.131/machine-learning/scikit-learn/iris/python-machine-learning-scikit-learn-iris-visualization-exercise-4.php