详解pandas.DataFrame.plot() 画图函数


Posted in Python onJune 14, 2020

首先看官网的DataFrame.plot( )函数

DataFrame.plot(x=None, y=None, kind='line', ax=None, subplots=False, 
        sharex=None, sharey=False, layout=None,figsize=None, 
        use_index=True, title=None, grid=None, legend=True, 
        style=None, logx=False, logy=False, loglog=False, 
        xticks=None, yticks=None, xlim=None, ylim=None, rot=None,
        xerr=None,secondary_y=False, sort_columns=False, **kwds)

参数详解如下:

Parameters:
x : label or position, default None#指数据框列的标签或位置参数

y : label or position, default None

kind : str
‘line' : line plot (default)#折线图
‘bar' : vertical bar plot#条形图
‘barh' : horizontal bar plot#横向条形图
‘hist' : histogram#柱状图
‘box' : boxplot#箱线图
‘kde' : Kernel Density Estimation plot#Kernel 的密度估计图,主要对柱状图添加Kernel 概率密度线
‘density' : same as ‘kde'
‘area' : area plot#不了解此图
‘pie' : pie plot#饼图
‘scatter' : scatter plot#散点图 需要传入columns方向的索引
‘hexbin' : hexbin plot#不了解此图

ax : matplotlib axes object, default None#**子图(axes, 也可以理解成坐标轴) 要在其上进行绘制的matplotlib subplot对象。如果没有设置,则使用当前matplotlib subplot**其中,变量和函数通过改变figure和axes中的元素(例如:title,label,点和线等等)一起描述figure和axes,也就是在画布上绘图。

subplots : boolean, default False#判断图片中是否有子图
Make separate subplots for each column

sharex : boolean, default True if ax is None else False#如果有子图,子图共x轴刻度,标签
In case subplots=True, share x axis and set some x axis labels to invisible; defaults to True if ax is None otherwise False if an ax is passed in; Be aware, that passing in both an ax and sharex=True will alter all x axis labels for all axis in a figure!

sharey : boolean, default False#如果有子图,子图共y轴刻度,标签
In case subplots=True, share y axis and set some y axis labels to invisible

layout : tuple (optional)#子图的行列布局
(rows, columns) for the layout of subplots

figsize : a tuple (width, height) in inches#图片尺寸大小

use_index : boolean, default True#默认用索引做x轴
Use index as ticks for x axis

title : string#图片的标题用字符串
Title to use for the plot

grid : boolean, default None (matlab style default)#图片是否有网格
Axis grid lines

legend : False/True/'reverse'#子图的图例,添加一个subplot图例(默认为True)
Place legend on axis subplots

style : list or dict#对每列折线图设置线的类型
matplotlib line style per column

logx : boolean, default False#设置x轴刻度是否取对数
Use log scaling on x axis
logy : boolean, default False
Use log scaling on y axis

loglog : boolean, default False#同时设置x,y轴刻度是否取对数
Use log scaling on both x and y axes

xticks : sequence#设置x轴刻度值,序列形式(比如列表)
Values to use for the xticks

yticks : sequence#设置y轴刻度,序列形式(比如列表)
Values to use for the yticks

xlim : 2-tuple/list#设置坐标轴的范围,列表或元组形式
ylim : 2-tuple/list

rot : int, default None#设置轴标签(轴刻度)的显示旋转度数
Rotation for ticks (xticks for vertical, yticks for horizontal plots)

fontsize : int, default None#设置轴刻度的字体大小
Font size for xticks and yticks

colormap : str or matplotlib colormap object, default None#设置图的区域颜色
Colormap to select colors from. If string, load colormap with that name from matplotlib.

colorbar : boolean, optional #图片柱子
If True, plot colorbar (only relevant for ‘scatter' and ‘hexbin' plots)

position : float  
Specify relative alignments for bar plot layout. From 0 (left/bottom-end) to 1 (right/top-end). Default is 0.5 (center)

layout : tuple (optional) #布局
(rows, columns) for the layout of the plot

table : boolean, Series or DataFrame, default False #如果为正,则选择DataFrame类型的数据并且转换匹配matplotlib的布局。
If True, draw a table using the data in the DataFrame and the data will be transposed to meet matplotlib's default layout. If a Series or DataFrame is passed, use passed data to draw a table.

yerr : DataFrame, Series, array-like, dict and str
See Plotting with Error Bars for detail.

xerr : same types as yerr.

stacked : boolean, default False in line and
bar plots, and True in area plot. If True, create stacked plot.

sort_columns : boolean, default False # 以字母表顺序绘制各列,默认使用前列顺序

secondary_y : boolean or sequence, default False ##设置第二个y轴(右y轴)
Whether to plot on the secondary y-axis If a list/tuple, which columns to plot on secondary y-axis

mark_right : boolean, default True
When using a secondary_y axis, automatically mark the column labels with “(right)” in the legend

kwds : keywords
Options to pass to matplotlib plotting method

Returns:axes : matplotlib.AxesSubplot or np.array of them

1、画图图形

import pandas as pd 

from pandas import DataFrame,Series

df = pd.DataFrame(np.random.randn(4,4),index = list('ABCD'),columns=list('OPKL'))

df
Out[4]: 
     O     P     K     L
A -1.736654 0.327206 -1.000506 1.235681
B 1.216879 0.506565 0.889197 -1.478165
C 0.091957 -2.677410 -0.973761 0.123733
D -1.114622 -0.600751 -0.159181 1.041668

详解pandas.DataFrame.plot() 画图函数 

注意一下散点图scatter是需要传入两个Y的columns参数的:

详解pandas.DataFrame.plot() 画图函数 

传入x,y参数

详解pandas.DataFrame.plot() 画图函数 

详解pandas.DataFrame.plot() 画图函数 

同时画多个子图,可以设置 subplot = True

详解pandas.DataFrame.plot() 画图函数 

2、注意事项:

- 在画图时,要注意首先定义画图的画布:fig = plt.figure( )
- 然后定义子图ax ,使用 ax= fig.add_subplot( 行,列,位置标)
- 当上述步骤完成后,可以用 ax.plot()函数或者 df.plot(ax = ax)
- 在jupternotebook 需要用%定义:%matplotlib notebook;如果是在脚本编译器上则不用,但是需要一次性按流程把代码写完;
- 结尾时都注意记录上plt.show()

详解pandas.DataFrame.plot() 画图函数

到此这篇关于详解pandas.DataFrame.plot() 画图函数的文章就介绍到这了,更多相关pandas.DataFrame.plot( )画图内容请搜索三水点靠木以前的文章或继续浏览下面的相关文章希望大家以后多多支持三水点靠木!

Python 相关文章推荐
python搭建简易服务器分析与实现
Dec 15 Python
Python实现批量修改文件名实例
Jul 08 Python
Python实现快速排序和插入排序算法及自定义排序的示例
Feb 16 Python
python 实时遍历日志文件
Apr 12 Python
python中实现迭代器(iterator)的方法示例
Jan 19 Python
基于python(urlparse)模板的使用方法总结
Oct 13 Python
Java分治归并排序算法实例详解
Dec 12 Python
python实现在图片上画特定大小角度矩形框
Oct 24 Python
Python实现最大子序和的方法示例
Jul 05 Python
Flask框架模板渲染操作简单示例
Jul 31 Python
浅谈Python2之汉字编码为unicode的问题(即类似\xc3\xa4)
Aug 12 Python
利用Python自动化操作AutoCAD的实现
Apr 01 Python
Pandas把dataframe或series转换成list的方法
Jun 14 #Python
详解pandas获取Dataframe元素值的几种方法
Jun 14 #Python
Pandas对DataFrame单列/多列进行运算(map, apply, transform, agg)
Jun 14 #Python
Python脚本破解压缩文件口令实例教程(zipfile)
Jun 14 #Python
pandas创建DataFrame的7种方法小结
Jun 14 #Python
Python中zipfile压缩文件模块的基本使用教程
Jun 14 #Python
pandas DataFrame运算的实现
Jun 14 #Python
You might like
第十二节--类的自动加载
2006/11/16 PHP
PHP中的strtr函数使用介绍(str_replace)
2011/10/20 PHP
通过PHP修改Linux或Unix口令的方法分享
2012/01/30 PHP
PHP中array_slice函数用法实例详解
2014/11/25 PHP
thinkPHP多表查询及分页功能实现方法示例
2017/07/03 PHP
PHP中类型转换 ,常量,系统常量,魔术常量的详解
2017/10/26 PHP
文字幻灯片
2006/06/26 Javascript
javascript中的prototype属性使用说明(函数功能扩展)
2010/08/16 Javascript
JS 无限级 Select效果实现代码(json格式)
2011/08/30 Javascript
jQuery之选择组件的深入解析
2013/06/19 Javascript
javascript设计模式之工厂模式示例讲解
2014/03/04 Javascript
JQuery设置时间段下拉选择实例
2014/12/30 Javascript
使用JavaScript脚本判断页面是否在微信中被打开
2016/03/06 Javascript
javascript实现抽奖程序的简单实例
2016/06/07 Javascript
原生js实现键盘控制div移动且解决停顿问题
2016/12/05 Javascript
简单实现nodejs上传功能
2017/01/14 NodeJs
分享十三个最佳JavaScript数据网格库
2017/04/07 Javascript
微信小程序商品到详情的实现
2017/06/27 Javascript
vue使用element-ui的el-input监听不了回车事件的解决方法
2018/01/12 Javascript
JS实现图片上传多次上传同一张不生效的处理方法
2018/08/06 Javascript
jquery ajax加载数据前台渲染方式 不用for遍历的方法
2018/08/09 jQuery
浅谈vue权限管理实现及流程
2020/04/23 Javascript
Vue 实现拨打电话操作
2020/11/16 Javascript
Saltstack快速入门简单汇总
2016/03/01 Python
python中的字典使用分享
2016/07/31 Python
Python语言描述最大连续子序列和
2017/12/05 Python
python单向循环链表原理与实现方法示例
2019/12/03 Python
python自动化发送邮件实例讲解
2021/01/04 Python
CSS3新增布局之: flex详解
2020/06/18 HTML / CSS
俄罗斯三星品牌商店:Samsungstore
2020/04/05 全球购物
预备党员党校学习自我评价分享
2013/11/12 职场文书
机关会计岗位职责
2014/04/08 职场文书
家长通知书家长评语
2014/04/17 职场文书
企业金融服务方案
2014/06/03 职场文书
个人工作总结(管理人员)范文
2019/08/13 职场文书
如何Tomcat中使用ipv6地址
2022/05/06 Servers