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
 

Go to:


PREV : 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.

Python Code Editor:

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

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.