matplotlib日常练习(1)

散点图

拿鸢尾花数据集来玩

iris = pd.read_csv('iris_dataset.csv', delimiter=',')
# 将种名映射为数值
iris['species'] = iris['species'].map({"setosa" : 0, "versicolor" : 1, "virginica" : 2})

plt.scatter(iris.petal_length, iris.petal_width, c=iris.species)

气泡图

上面图的基础上改改就是气泡图

plt.scatter(iris.petal_length, iris.petal_width, s=50*iris.petal_length*iris.petal_width, 
            c=iris.species, alpha=0.3)

堆叠图

x = np.array([1, 2, 3, 4, 5, 6], dtype=np.int32)
Apr = [5, 7, 6, 8, 7, 9]
May = [0, 4, 3, 7, 8, 9]
June = [6, 7, 4, 5, 6, 8]

labels = ["April ", "May", "June"]

fig, ax = plt.subplots()
ax.stackplot(x, Apr, May, June, labels=labels)
ax.legend(loc=2)

plt.xlabel('defect reason code')
plt.ylabel('number of defects')
plt.title('Product Defects - Q1 FY2019')

饼图

labels = ['SciFi', 'Drama', 'Thriller', 'Comedy', 'Action', 'Romance']
sizes = [5, 15, 10, 20, 40, 10]   # Add upto 100%
explode = (0, 0, 0, 0, 0.1, 0)  # only "explode" the 2nd slice (i.e. 'Hogs')

fig1, ax1 = plt.subplots()
ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',
        shadow=True, startangle=90)

你可能感兴趣的:(matplotlib日常练习(1))