上QQ阅读APP看书,第一时间看更新
How to do it...
The following code block plots a bubble plot, for which we have seen a scatter plot earlier:
- Load the Iris dataset:
iris = pd.read_csv('iris_dataset.csv', delimiter=',')
- In the file, each class of species is defined as 0, 1, and 2, which we will map to their descriptive names:
iris['species'] = iris['species'].map({"setosa" : 0, "versicolor" :
1, "virginica" : 2})
- Draw the scatter plot:
plt.scatter(iris.petal_length, iris.petal_width,
s=50*iris.petal_length*iris.petal_width,
c=iris.species,
alpha=0.3)
- Label the x and y axes:
plt.xlabel('petal length')
plt.ylabel('petal width')
- Display the graph on the screen:
plt.show()