Matplotlib 3.0 Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it...

The following code block plots a bubble plot, for which we have seen a scatter plot earlier:

  1. Load the Iris dataset:
iris = pd.read_csv('iris_dataset.csv', delimiter=',')
  1. 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})
  1. 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)
  1. Label the x and y axes:
plt.xlabel('petal length')
plt.ylabel('petal width')
  1. Display the graph on the screen:
plt.show()