5.1 作图的重要性在分析一个数据之前, 我们首先要对数据进行检查, 在统计上看一下汇总统计, 比如最大值, 最小值, 中位数, 平均值, 方差, 标准差, 变异系数等等.
所谓一图胜千言. python中的作图工具
5.2 散点图# Import standard packagesimport numpy as npimport matplotlib.pyplot as pltimport pandas as pdimport scipy.stats as statsimport seaborn as sns 这里生成了500个随机数, 使用plot进行作图 # 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); 练习corn.csvcorn是R包agridat中的smith.corn.uniformity玉米数据, 我们来看一下如何对其可视化? 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读取数据, 使用pandas包 import pandas as pd corn = pd.read_csv("d:/corn.csv") 查看前六行 corn.head()
对产量yield作图 import matplotlib.pyplot as plt c1 = plt.plot(corn["yield"],".") c2 = plt.hist(corn["yield"]) c3 = plt.boxplot(corn["yield"])
|
|