5.1 作圖的重要性在分析一個(gè)數(shù)據(jù)之前, 我們首先要對(duì)數(shù)據(jù)進(jìn)行檢查, 在統(tǒng)計(jì)上看一下匯總統(tǒng)計(jì), 比如最大值, 最小值, 中位數(shù), 平均值, 方差, 標(biāo)準(zhǔn)差, 變異系數(shù)等等.
所謂一圖勝千言. python中的作圖工具
5.2 散點(diǎn)圖# Import standard packagesimport numpy as npimport matplotlib.pyplot as pltimport pandas as pdimport scipy.stats as statsimport seaborn as sns這里生成了500個(gè)隨機(jī)數(shù), 使用plot進(jìn)行作圖 # Generate the data
x = np.random.randn(500)
# Plot-command start ---------------------
plt.plot(x, '.')
# Plot-command end -----------------------
# Show plot
a2 = plt.show()5.3 直方圖a3 = plt.hist(x,bins=25)5.4 箱線圖a4 = plt.boxplot(x);練習(xí)corn.csvcorn是R包agridat中的smith.corn.uniformity玉米數(shù)據(jù), 我們來看一下如何對(duì)其可視化? row col plot year yield
1 20 1 101 95 30.0
2 19 1 102 95 29.1
3 18 1 103 95 25.7
4 17 1 104 95 26.3
5 16 1 105 95 30.3
6 15 1 106 95 31.1首先, 在R中將其保存為corn.csv, 保存到D盤根目錄(方便讀取) library(agridat)
data(smith.corn.uniformity)
dat = smith.corn.uniformity
head(dat)
write.csv(dat,"d:/corn.csv",row.names = F)用python讀取數(shù)據(jù), 使用pandas包 import pandas as pdcorn = pd.read_csv("d:/corn.csv")查看前六行 corn.head()
對(duì)產(chǎn)量yield作圖 import matplotlib.pyplot as pltc1 = plt.plot(corn["yield"],".")c2 = plt.hist(corn["yield"])c3 = plt.boxplot(corn["yield"])
|
|
|