官术网_书友最值得收藏!

Scatter plot using seaborn

A scatter plot can also be generated using the seaborn library. Seaborn makes the graph visually better. We can illustrate the relationship between x and y for distinct subsets of the data by utilizing the size, style, and hue parameters of the scatter plot in seaborn.

Get more detailed information about the parameters from seaborn's documentation website: https://seaborn.pydata.org/generated/seaborn.scatterplot.html.

Now, let's load the Iris dataset:

df = sns.load_dataset('iris')

df['species'] = df['species'].map({'setosa': 0, "versicolor": 1, "virginica": 2})
sns.scatterplot(x=df["sepal_length"], y=df["sepal_width"], hue=df.species, data=df)

The scatter plot generated from the preceding code is as follows:

In the preceding plot, we can clearly see there are three species of flowers indicated by three distinct colors. It is more clear from the diagram how different specifies of flowers vary in terms of the sepal width and the length. 

主站蜘蛛池模板: 景泰县| 昭觉县| 澜沧| 永福县| 武冈市| 青海省| 峨边| 崇明县| 顺平县| 琼海市| 长兴县| 蒙自县| 敖汉旗| 突泉县| 澄城县| 清苑县| 乐至县| 宁远县| 扬州市| 招远市| 河曲县| 阿勒泰市| 象州县| 富裕县| 建平县| 平凉市| 岳西县| 日土县| 柏乡县| 皋兰县| 寿阳县| 吉林市| 永福县| 绍兴市| 西吉县| 博客| 苏尼特右旗| 九寨沟县| 铜陵市| 东乌珠穆沁旗| 玉溪市|