DataCamp学习笔记003 -Matplotlib常用画图方法

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)–为图表添加文字信息
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值