广西桂平建设局网站,站优云网络公司,自动设计logo的软件,上海网站建设的网站一、可视化概述在Python中#xff0c;常见的数据可视化库有3个#xff1a;matplotlib#xff1a;最常用的库#xff0c;可以算作可视化的必备技能库#xff0c;比较底层#xff0c;api多,学起来不太容易。seaborn#xff1a;是建构于matplotlib基础上#xff0c;能满足… 一、可视化概述在Python中常见的数据可视化库有3个matplotlib最常用的库可以算作可视化的必备技能库比较底层api多,学起来不太容易。seaborn是建构于matplotlib基础上能满足绝大多数可视化需求更特殊的需求还是需要学习matplotlib。pyecharts上面的两个库都是静态的可视化库而pyecharts有很好的web兼容性可以做到可视化的动态效果。并且种类也比较丰富。比如这个图就非常厉害画图神器pyecharts-旭日图Pandas而今天要讲的是Pandas的可视化Pandas主要作为数据分析的库虽然没有上述三个库那个强大但是胜在方便在数据分析的过程中只要一行代码就能实现。并且图形也非常漂亮。二、直接看案例Pandas 中有11个比较常见的图形可视化还有几个比较进阶的我们一个一个看看怎么画的import pandas as pdimport numpy as npdf pd.DataFrame(np.random.rand(10, 4), columns[A,B,C,D])01、柱状图-纵向df.plot.bar() stackedTrue画堆叠柱状图df.plot.bar(stackedTrue) 02、柱状图-横向df.plot.barh() 同样stackedTrue画堆叠柱状图df.plot.barh(stackedTrue) 03、面积图df.plot.area(alpha 0.9) df.plot.area(stackedTrue,alpha 0.9) 04、密度图-kdedf.plot.kde() 05、密度图-densitydf.plot.density() 06、直方图换个数据集df pd.DataFrame({A: np.random.randn(1000) 1, B: np.random.randn(1000), C: np.random.randn(1000) - 1}, columns[A, B, C]) df.plot.hist(bins200) df.plot.hist(stackedTrue, bins20) df pd.DataFrame(np.random.rand(1000, 4), columns[A,B,C,D])df.diff().hist(colork, alpha0.7, bins50) 07、箱盒图df pd.DataFrame(np.random.rand(100, 4), columns[A,B,C,D])df.plot.box() vertFalse也可以换成横向df.plot.box(vertFalse) 08、散点图df.plot.scatter(xA,yB) 09、蜂巢图df pd.DataFrame(np.random.randn(1000, 2), columns[a, b])df[b] df[b] np.arange(1000)df.plot.hexbin(xa, yb, gridsize25) 07、饼图series pd.Series(3 * np.random.rand(4), index[a, b, c, d], nameseries)series.plot.pie(figsize(6, 6)) series.plot.pie(labels[AA, BB, CC, DD], colors[r, g, b, c],autopct%.2f, fontsize20, figsize(6, 6)) 08、矩阵散点图from pandas.plotting import scatter_matrixdf pd.DataFrame(np.random.randn(1000, 4), columns[a, b, c, d])scatter_matrix(df, alpha0.2, figsize(6, 6), diagonalkde) 09、安德鲁斯曲线加载自己的数据关注公众号【AI入门学习】回复 iris 获取数据集data pd.read_csv(C:/Users/wuzhengxiang/Desktop/iris.csv)pd.plotting.andrews_curves(data , Name) andrews_curves(data, Name, colormapwinter) 10、平行坐标图该图也是使用自己加载的iris数据集from pandas.plotting import parallel_coordinatesparallel_coordinates(data, Name, colormapgist_rainbow) 11、Lag Plotfrom pandas.plotting import lag_plotdf pd.Series(0.1 * np.random.rand(1000) 0.9 * np.sin(np.linspace(-99 * np.pi, 99 * np.pi, num1000)))lag_plot(df) 12、默认函数plot直接画图默认为折线图df pd.DataFrame(np.random.rand(12, 4), columns[A,B,C,D])df.plot() df.plot(subplotsTrue,layout(2, 2), figsize(15, 8)) df pd.DataFrame(np.random.rand(1000, 4), columns[A,B,C,D])df.plot() df.plot(subplotsTrue,layout(2, 2), figsize(15, 8)) 13、bootstrap_plots pd.Series(np.random.uniform(size100))pd.plotting.bootstrap_plot(s) 三、参数详解1、官方文档https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.plot.htmlhttps://pandas.pydata.org/pandas-docs/version/0.18.1/visualization.html2、参数介绍DataFrame.plot(xNone, yNone, kindline, axNone, subplotsFalse, sharexNone, shareyFalse, layoutNone, figsizeNone, use_indexTrue, titleNone, gridNone, legendTrue, styleNone, logxFalse, logyFalse, loglogFalse, xticksNone, yticksNone, xlimNone, ylimNone, rotNone, fontsizeNone, colormapNone, position0.5, tableFalse, yerrNone,xerrNone, stackedTrue/False, sort_columnsFalse, secondary_yFalse, mark_rightTrue, **kwds)e, legendTrue, styleNone, logxFalse, logyFalse, loglogFalse, xticksNone, yticksNone, xlimNone, ylimNone, rotNone, fontsizeNone, colormapNone, position0.5, tableFalse, yerrNone, xerrNone, stackedTrue/False, sort_columnsFalse, secondary_yFalse, mark_rightTrue, **kwds)注意每种绘图类型都有相对应的方法: df.plot(kindline)与df.plot.line()等价x : label or position, default None#指数据列的标签或位置参数y : label, position or list of label, positions, default Nonekind : str#绘图类型‘line’ : line plot (default)#折线图‘bar’ : vertical bar plot#条形图。stacked为True时为堆叠的柱状图‘barh’ : horizontal bar plot#横向条形图‘hist’ : histogram#直方图(数值频率分布)‘box’ : boxplot#箱型图‘kde’ : Kernel Density Estimation plot#密度图主要对柱状图添加Kernel 概率密度线‘density’ : same as ‘kde’‘area’ : area plot#与x轴所围区域图(面积图)。StackedTrue时每列必须全部为正或负值stackedFalse时对数据没有要求‘pie’ : pie plot#饼图。数值必须为正值需指定Y轴或者subplotsTrue‘scatter’ : scatter plot#散点图。需指定X轴Y轴‘hexbin’ : hexbin plot#蜂巢图。需指定X轴Y轴‘hexbin’ : hexbin plot#蜂巢图。需指定X轴Y轴ax : matplotlib axes object, default None#**子图(axes, 也可以理解成坐标轴) 要在其上进行绘制的matplotlib subplot对象。如果没有设置则使用当前matplotlib subplot**其中变量和函数通过改变figure和axes中的元素(例如title,label,点和线等等)一起描述figure和axes也就是在画布上绘图。subplots : boolean, default False#是否对列分别作子图sharex : boolean, default True if ax is None else False#如果ax为None则默认为True否则为FalseIn case subplotsTrue, 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 sharexTrue will alter all x axis labels for all axis in a figure!sharey : boolean, default False#如果有子图子图共y轴刻度标签In case subplotsTrue, share y axis and set some y axis labels to invisiblelayout : tuple (rows, columns) for the layout of subplots#子图的行列布局figsize : a tuple (width, height) in inches#图片尺寸大小use_index : boolean, default True#默认用索引做x轴title : string#图片的标题用字符串Title to use for the plotgrid : boolean, default None#图片是否有网格legend : False/True/’reverse’#子图的图例 (默认为True)style : list or dict#对每列折线图设置线的类型logx : boolean, default False#设置x轴刻度是否取对数logy : boolean, default Falseloglog : boolean, default False#同时设置xy轴刻度是否取对数xticks : sequence#设置x轴刻度值序列形式(比如列表)yticks : sequence#设置y轴刻度序列形式(比如列表)xlim : float/2-tuple/list#设置坐标轴的范围。数值(最小值)列表或元组(区间范围)ylim : float/2-tuple/listrot : int, default None#设置轴标签(轴刻度)的显示旋转度数 fontsize : int, default None#设置轴刻度的字体大小colormap : str or matplotlib colormap object, default None#设置图的区域颜色colorbar : boolean, optional #柱子颜色If True, plot colorbar (only relevant for ‘scatter’ and ‘hexbin’ plots)position : float #条形图的对齐方式取值范围[0,1]即左下端到右上端默认0.5(中间对齐) layout : tuple (optional) #布局。layout(2, 3)两行三列layout(2, -1)两行自适应列数Eg. df.plot(subplotsTrue, layout(2, -1), sharexFalse)table : boolean, Series or DataFrame, default False #图下添加表。如果为True则使用DataFrame中的数据绘制表格并且数据将被转置以满足matplotlib的默认布局。。yerr : DataFrame, Series, array-like, dict and strSee 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-axismark_right : boolean, default True往期精彩回顾适合初学者入门人工智能的路线及资料下载机器学习及深度学习笔记等资料打印机器学习在线手册深度学习笔记专辑《统计学习方法》的代码复现专辑AI基础下载机器学习的数学基础专辑获取本站知识星球优惠券复制链接直接打开https://t.zsxq.com/qFiUFMV本站qq群704220115。加入微信群请扫码