﻿ Python Machine learning Scikit-learn: Create a graph to find relationship between the petal length and width - w3resource

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

## Python Machine learning Iris Visualization: Exercise-5 with Solution

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

Sample Solution:

Python Code:

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

Output:

```
```

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?

﻿