DataCamp学习笔记[Notes- Intermediate Python for Data Science_1]
1. Matplotlib常用画图方法[PART 1]:
- plt.plot() --可利用Matplotlib绘制简单line plot
In[1]:df = pd.read_csv("http://archive.ics.uci.edu/ml/machine-learning- databases/iris/iris.data",
header=None,
names = ["sepal_length","sepal_width","petal_length","petal_width", "species"])
In[2]:df.plot(x = "sepal_length", y = "sepal_width")
...:plt.show()
In[3]:df[["sepal_length","sepal_width"]].plot()
...:plt.show()
(上图无实际意义,仅为展示line plot 的两种作图方法)
- plt.scatter() --可利用Matplotlib绘制简单散点图
In[4]:plt.scatter(data = df, x = "sepal_length", y = "sepal_width")
...:plt.show()
- df.plot(kind = ‘hist’); df.plt.hist(); df.hist() – 三种绘制直方图方法基本相同,此处bins参数指代组数,range参数指代x_scale,normed参数指代是否标准化。
下图为PDF方法(Probability Density Functions)【不累加】:
In[5]:df["sepal_length"].plot(kind = 'hist', bins =20, range = (4,8), normed = True)
下图为CDF方法(Cumulative Density Functions)【累加】此处设置cumulative参数为True,默认False:
In[5]:df["sepal_length"].plot(kind = 'hist', bins =20, range = (4,8), normed = True, cumulative = True)
- plt.boxplot() – 利用Matplotlib绘制箱线图
In[6]:plt.boxplot(df["sepal_length"])
- plt.clf() – 清除作图区域
- plt.xlabel() --设置x轴标签
- plt.ylabel() --设置y轴标签
- plt.title()–设置图表标题
- plt.ytick(ticks=None, labels=None)–设置y轴性质
- plt.xtick(ticks=None, labels=None)–设置x轴性质
- plt.text(x, y, s)–为图表添加文字信息