详解pandas.DataFrame.plot() 画图函数
作者:brucewong0516 发布时间:2021-06-02 21:41:49
标签:pandas.DataFrame.plot(),画图
首先看官网的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
注意一下散点图scatter是需要传入两个Y的columns参数的:
传入x,y参数
同时画多个子图,可以设置 subplot = True
2、注意事项:
- 在画图时,要注意首先定义画图的画布:fig = plt.figure( )
- 然后定义子图ax ,使用 ax= fig.add_subplot( 行,列,位置标)
- 当上述步骤完成后,可以用 ax.plot()函数或者 df.plot(ax = ax)
- 在jupternotebook 需要用%定义:%matplotlib notebook;如果是在脚本编译器上则不用,但是需要一次性按流程把代码写完;
- 结尾时都注意记录上plt.show()
来源:https://blog.csdn.net/brucewong0516/article/details/80524442
0
投稿
猜你喜欢
- 逐步指示这是提供给更喜欢阅读的人的视频文本版本。我们将创建一个类似黑客新闻 或Reddit的社交新闻网站。它将被称为“钢铁传闻”,作为一个分
- 1.创建数据库连接,并打开set cnn=Server.CreateObject("ADODB.Connection&q
- 重复的数据可能有这样两种情况,第一种: 表中只有某些字段一样,第二种是两行记录完全一样。一、对于部分字段重复数据的删除 1.查询重复的数据
- 本文实例讲述了Django框架中间件(Middleware)用法。分享给大家供大家参考,具体如下:1、面向切面编程切点(钩子)切点允许我们动
- 问题你需要将一个Python对象序列化为一个字节流,以便将它保存到一个文件、存储到数据库或者通过网络传输它。解决方案对于序列化最普遍的做法就
- 扪心自问,你真正了解你卖给用户的是什么玩意么?你所认为革命性的,一定会震惊世界的功能、特色,用户真的买单么?我的意思是,我们总是习惯性的忘记
- opencv-python打开USB或笔记本前置摄像头代码其中video_index是摄像头编号,一般前置摄像头为0,USB摄像头为1或2.
- 前言常见的通知方式有:邮件,电话,短信,微信。短信和电话:通常是收费的,较少使用;邮件:适合带文件类型的通知,较正式,存档使用;微信:适合告
- turtle库是python的基础绘图库,官方手册这个库被介绍为一个最常用的用来给孩子们介绍编程知识的方法库,其主要是用于程序设计入门,是标
- 本文实例讲述了python实现查找两个字符串中相同字符并输出的方法。分享给大家供大家参考。具体实现方法如下:seq1 = "spa
- 前言朋友提问:创建Word文档并插入市面上有很多图表绘制库,例如echarts和highcharts等等。对于这种由js动态绘制的图表,我们
- Python web应用想要发布使用iis发布有两种方式,这篇文章就为大家介绍一下这两种方式的具体实现:1.配置HttpPlatform程序
- 本文实例为大家分享了python网络爬虫的笔记,供大家参考,具体内容如下(一) 三种网页抓取方法1、 正则
- 话不多说,小工具需求如下: 功能需求 -- 电脑开机后自动执行时间同步 非功能需求 -- 安装执行简单,无需安装额外环境一、代码实现基于以上
- 前段时间我通过观察韩国网站和其他作品发现了普遍存在黄金分割这样一个规律,不过只跟色相有关,明度、纯度还没做研究,今天看到论坛一篇“网页配色之
- 还有种片面的观点认为,做网站设计与平面差不多,比如老罗发布的这则招聘中提到:年薪十万招擅长做下列网站设计风格的平面设计师一名。在专业角度,网
- 前几天,为了增强本站的SEO,着手把另一个域名:www.aspxhome.com下的所有页面301转向到www.cidianwang.com
- 摘要: Portal是IT领域的新技术,是企业信息化工作的发展方向之一。本文首先介绍了Oracle Portal的定义、特点,接着阐述了po
- 以前跟同事开玩笑时说过,我们遇到的用户在访谈测试过程中的表现基本上就三种类型,发泄型,赞美型和实话实说型。发泄型用户通常是在产品的使用过程中
- 一.雅黑设计理念 雅黑字体是为微软公司设计的屏幕显示汉字。它具有个性独特、结体优美、识别性强、块状效果好、显示清晰等优点。在当今数字化时代更