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

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. 

主站蜘蛛池模板: 古蔺县| 噶尔县| 寿宁县| 广东省| 阳曲县| 陆丰市| 冷水江市| 资溪县| 木里| 肥城市| 五华县| 苏尼特左旗| 济阳县| 南溪县| 苏尼特左旗| 漳州市| 牡丹江市| 全椒县| 肇庆市| 神农架林区| 洪雅县| 泸溪县| 故城县| 明光市| 洪雅县| 紫云| 延安市| 法库县| 汉源县| 鸡东县| 永安市| 鸡泽县| 敖汉旗| 重庆市| 大余县| 新巴尔虎左旗| 若尔盖县| 精河县| 平谷区| 九龙县| 蒙阴县|