【笔记】使用matplotlib进行绘图

导入并加载数据

import pandas as pd
% matplotlib inline
df_powerplant=pd.read_csv('powerplant_data_edited.csv')

绘制湿度的图

df_powerplant['Relative Humidity'].hist(figsize(8,8))  #直方图的尺寸
#df_powerplant['Relative Humidity'].plot(kind='hist') 
df_powerplant['Relative Humidity'].plot(kind='pie') #饼状图
df_powerplant['Relative Humidity'].plot(kind='scatter') #散点图
df_powerplant['Relative Humidity'].plot(kind='bar') #柱形图
df_powerplant['Relative Humidity'].plot(kind='box')  #箱线
#df_powerplant['Relative Humidity'].value_counts() 显示每个唯一值的数量

*all变量之间的关系

pd.plotting.scatter_matrix( df_powerplant,figsize(15,15))

绘制温度与电力输出之间的关系图

df_powerplant.plot(x='Temperature',y='Electrical output',kind='scatter')

用 Matplotlib 创建柱状图

import matplotlib.pyplot as plt
% matplotlib inline

使用 pyplot 的 bar 函数

plt.bar([1, 2, 3], [224, 620, 425])

在这里插入图片描述
可以利用 pyplot 的 xticks 功能,或通过在 bar 功能中指定另一个参数,指定 x 轴刻度标签。以下两个框的结果相同。

#绘制条柱
plt.bar([1, 2, 3], [224, 620, 425])

#为 x 轴指定刻度标签及其标签
plt.xticks([1, 2, 3], ['a', 'b', 'c'])

在这里插入图片描述

#用 x 轴的刻度标签绘制条柱
plt.bar([1, 2, 3], [224, 620, 425], tick_label=['a', 'b', 'c']);

在这里插入图片描述
#用以下方法设置轴标题和标签

plt.bar([1, 2, 3], [224, 620, 425], tick_label=['a', 'b', 'c'])
plt.title('Some Title')
plt.xlabel('Some X Label')
plt.ylabel('Some Y Label');

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值