当前位置:   article > 正文

用Matplotlib与Seaborn画散点图并创建图例_matplotlib 散点图 图例

matplotlib 散点图 图例

Matplotlib与Seaborn是在python中很常用的两个画图库。

安装两个库

pip install matplotlib
pip install seaborn
  • 1
  • 2

用Matplotlib画散点图

import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns  
import pandas as pd
  • 1
  • 2
  • 3
  • 4

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

生成颜色字典

species_group = iris.groupby("species")  
color_used = ["red", "green", "blue"]  
colors = dict(zip(species_group.count().index, color_us
  • 1
  • 2
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/346631
推荐阅读
相关标签
  

闽ICP备14008679号