52 lines
1.2 KiB
Python
52 lines
1.2 KiB
Python
import pandas as pd
|
|
import matplotlib.pyplot as plt
|
|
|
|
df = pd.read_csv("iris1.csv", encoding="gbk")
|
|
# 0=sepal_ler 1=sepal_w 2=petal_l 3=petal_w 4=species
|
|
col0 = df.iloc[:,0]
|
|
col1 = df.iloc[:,1]
|
|
col2 = df.iloc[:,2]
|
|
col3 = df.iloc[:,3]
|
|
col4 = df.iloc[:,4]
|
|
|
|
plt.rcParams["font.sans-serif"] = ["SimHei"]
|
|
plt.rcParams["axes.unicode_minus"] = False
|
|
plt.figure(figsize=(18,12))
|
|
|
|
#1 sepal散点
|
|
plt.subplot(3,3,1)
|
|
for sp in col4.unique():
|
|
idx = col4==sp
|
|
plt.scatter(col0[idx],col1[idx],label=sp)
|
|
plt.title("sepal花萼散点图")
|
|
plt.legend()
|
|
|
|
#2 petal散点
|
|
plt.subplot(3,3,2)
|
|
for sp in col4.unique():
|
|
idx = col4==sp
|
|
plt.scatter(col2[idx],col3[idx],label=sp)
|
|
plt.title("petal花瓣散点图")
|
|
plt.legend()
|
|
|
|
#3 三个直方图
|
|
sps = col4.unique()
|
|
plt.subplot(3,3,4)
|
|
plt.hist(col2[col4==sps[0]])
|
|
plt.title(f"{sps[0]}直方图")
|
|
|
|
plt.subplot(3,3,5)
|
|
plt.hist(col2[col4==sps[1]])
|
|
plt.title(f"{sps[1]}直方图")
|
|
|
|
plt.subplot(3,3,6)
|
|
plt.hist(col2[col4==sps[2]])
|
|
plt.title(f"{sps[2]}直方图")
|
|
|
|
#4 setosa折线
|
|
plt.subplot(3,3,7)
|
|
plt.plot(col0[col4=="setosa"],marker='o')
|
|
plt.title("setosa叶长折线图")
|
|
|
|
plt.tight_layout()
|
|
plt.show() |