Matplotlib与Seaborn是在python中很常用的两个画图库。
安装两个库
pip install matplotlib
pip install seaborn
用Matplotlib画散点图
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
从seaborn上面加载文档
iris = sns.load_dataset("iris")
print(iris.head())
sepal_length sepal_width petal_length petal_width species
0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
4 5.0 3.6 1.4 0.2 setosa
生成颜色字典
species_group = iris.groupby("species")
color_used = ["red", "green", "blue"]
colors = dict(zip(species_group.count().index, color_us