import pandas as pd
pd.plotting.register_matplotlib_converters()
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
print("Setup Complete")
Setup Complete
# Path of the file to read
iris_filepath = "./iris.csv"
# Read the file into a variable iris_data
iris_data = pd.read_csv(iris_filepath, index_col="Id")
# Print the first 5 rows of the data
iris_data.head()
可以使用sns.distplot
来绘制直方图
# Histogram
sns.distplot(a=iris_data['Petal Length (cm)'], kde=False)
/opt/conda/lib/python3.6/site-packages/seaborn/distributions.py:2551: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms).
warnings.warn(msg, FutureWarning)
<AxesSubplot:xlabel='Petal Length (cm)'>
在sns.distplot
中有两个参数
a=
选择一个plot(在这个case中,我们选择Petal Length (cm))kde=False
在绘制直方图的时候,通常会绘制另一个图表(密度图),不过这边暂时不需要下一个图表是密度图,可以当作是比较缓和的直方图
# KDE plot
sns.kdeplot(data=iris_data['Petal Length (cm)'], shade=True)
<AxesSubplot:xlabel='Petal Length (cm)', ylabel='Density'>
data=
代表说需要用到的资料shade=
代表说要在图表下方加上颜色我们并不限制於单一columns的密度图,也可以创造二维的密度图
# 2D KDE plot
sns.jointplot(x=iris_data['Petal Length (cm)'], y=iris_data['Sepal Width (cm)'], kind="kde", shade=True)
<seaborn.axisgrid.JointGrid at 0x7f405a194710>
在这个部分我们要将不同种类的图加在一起
先将资料分为三个部分读取
# Paths of the files to read
iris_set_filepath = "./iris_setosa.csv"
iris_ver_filepath = "./iris_versicolor.csv"
iris_vir_filepath = "./iris_virginica.csv"
# Read the files into variables
iris_set_data = pd.read_csv(iris_set_filepath, index_col="Id")
iris_ver_data = pd.read_csv(iris_ver_filepath, index_col="Id")
iris_vir_data = pd.read_csv(iris_vir_filepath, index_col="Id")
# Print the first 5 rows of the Iris versicolor data
iris_ver_data.head()
我们使用sns.distplot
三次来显示三种资料
并且用label=
来将资料的名称显示瑜说明栏
# Histograms for each species
sns.distplot(a=iris_set_data['Petal Length (cm)'], label="Iris-setosa", kde=False)
sns.distplot(a=iris_ver_data['Petal Length (cm)'], label="Iris-versicolor", kde=False)
sns.distplot(a=iris_vir_data['Petal Length (cm)'], label="Iris-virginica", kde=False)
# Add title
plt.title("Histogram of Petal Lengths, by Species")
# Force legend to appear
plt.legend()
<matplotlib.legend.Legend at 0x7f405a5ab9b0>
为了要让说明栏显示,要加上plt.legend()
我们也可以使用kdeplot来呈现多个图表
# KDE plots for each species
sns.kdeplot(data=iris_set_data['Petal Length (cm)'], label="Iris-setosa", shade=True)
sns.kdeplot(data=iris_ver_data['Petal Length (cm)'], label="Iris-versicolor", shade=True)
sns.kdeplot(data=iris_vir_data['Petal Length (cm)'], label="Iris-virginica", shade=True)
# Add title
plt.title("Distribution of Petal Lengths, by Species")
Text(0.5, 1.0, 'Distribution of Petal Lengths, by Species')
<<: day21 开分支,浅谈kotlin paging3 with flow
>>: Day-25 Hash Function(杂凑函数), 乘法杂凑法, 除法杂凑法
废话不多说,我们直接看文件~XD 文件 文件原文:Cache and TLB Flushing Un...
一、究竟AI能不能预测股价? 不能 好了,被我骗进来的可以按上一页了(X 结论已经讲了,如果你对原因...
Salom,我是Charlie! 在Day20的时候我们完成了createOrder跟Capture...
事件处理 事件处理就是当使用者对画面做了一个动作,我们的程序必须侦测这个动作,并且做出反应。 如果事...
今天我们继续学习watch os的开发。 正文 上面所展示的是按下Button之後会将下面的Text...