Merge pull request '数据可视化' (#6) from 盘荣博 into main
commit
a1f852b393
Before Width: | Height: | Size: 47 KiB After Width: | Height: | Size: 824 KiB |
After Width: | Height: | Size: 2.7 MiB |
@ -1,9 +1,42 @@
|
||||
import pandas as pd
|
||||
from scipy.stats import zscore
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib.pyplot import ylabel
|
||||
df = pd.read_excel("棉花产量论文作业的数据.xlsx")
|
||||
plt.plot(df["年份"],df["单产"])
|
||||
# plt.plot(df["年份"],df["单产"])
|
||||
plt.rcParams['font.sans-serif']="SimHei"
|
||||
plt.ylabel('单产')
|
||||
plt.xlabel('年份')
|
||||
# plt.rcParams['size'] =10
|
||||
# plt.ylabel('单产')
|
||||
# plt.xlabel('年份')
|
||||
|
||||
# print(df)
|
||||
d = df.to_numpy()[:,1:]
|
||||
print(d)
|
||||
plt.subplot(4,1,1)
|
||||
plt.scatter(d[:,:1],d[:,1:2],c='r')
|
||||
ylabel('原始数据'),plt.title("单产和种子费用的关系")
|
||||
#公式调用标准化,遵守标准正态分布
|
||||
data = zscore(d)
|
||||
print(data)
|
||||
plt.subplot(4,1,2)
|
||||
plt.scatter(data[:,:1],data[:,1:2],c='b',)
|
||||
ylabel('zscore')
|
||||
|
||||
print(d.max(axis=0))
|
||||
print(d.std(axis=0))
|
||||
print(d.mean(axis=0))
|
||||
#手写标准正态分布
|
||||
data1=(d-d.mean(axis=0))/d.std(axis=0)
|
||||
print(data1)
|
||||
plt.subplot(4,1,3)
|
||||
plt.scatter(data1[:,:1],data1[:,1:2],c='y')
|
||||
ylabel('手写标准正态分布')
|
||||
|
||||
data2=(d-d.min(axis=0))/(d.max(axis=0)-d.min(axis=0))
|
||||
plt.subplot(4,1,4)
|
||||
plt.scatter(data2[:,:1],data2[:,1:2],c='g')
|
||||
plt.xlabel('压缩到0~1')
|
||||
print(data==data1)
|
||||
|
||||
plt.savefig("shuju.jpg",dpi=2000)
|
||||
plt.show()
|
||||
print(df)
|
Loading…
Reference in new issue