1说明: 1。1GooPyCharts,它是一个用于谷歌图表接口的Python包。 1。2一个易于安装与使用的图表库,语法与MATLAB相似,而且可以替代matplotlib。 1。3可以保存为PNG、HTML,数据可导出CSV。 1。4代码简单,使用方便,支持中文,讲解在代码的注释中。 1。5源代码是适合jupyter中的,适当修改代码,适合普通python的脚本代码,启动微软编辑器运行。 2准备: 2。1环境: 华为笔记本电脑、深度deepinlinux操作系统、python3。8和微软vscode编辑器。 2。2传送门:https:github。comDfenestratorGooPyCharts 2。3安装:pipinstallgpcharts注意是gpcharts,不是goopycharts本机安装sudopip3。8installgpcharts附带安装pipinstallfuture本机安装sudopip3。8installfuture 3散点图Scatter: 3。1代码:fromgpchartsimportfigurefigfigure(StrongCorrelation)默认参数:标题名,x坐标轴标签名,y坐标轴标签名,大小设置figure(titleFig,xlabel,ylabel,height600,width1000)趋势线trendlineTrue,一条对角直线,默认是不显示,显示后,会得到计算大概公式显示在图例右侧fig。scatter(〔1,2,3,4,5〕,〔〔2,3〕,〔1,2〕,〔5,4〕,〔3,5〕,〔4,2〕〕)参数:x数据,y数据:上述2组figure。scatter(xdata,ydata〔〕,trendlineFalse,dispTrue)wbwebbrowseweb浏览器打开fig。wb() 3。2效果图: 4线图line: 4。1代码:fromgpchartsimportfigure指定参数figfigure(titlePopulationGrowth,ylabelPopulation,xlabel世纪,height600,width600)figfigure(titlePopulationGrowth,ylabelPopulation,height600,width600)注意这里:世纪年度就是xlabel,所以上面的xlabel就不需要设置,如果设置,也不会显示,以这个为主xVals〔世纪年度,1700,1800,1900,2000〕支持中文指定2组数据的对应的名称yVals〔〔GothamCity,CentralCity〕,〔0,10〕,〔100,200〕,〔100000,500000〕,〔5000000,10000000〕〕logScaleFalse,默认是不显示,显示的话,那么y值以对数形式标尺,比如:1E11E7注意plot默认是line曲线图fig。plot(xVals,yVals,logScaleTrue,)参数figure。plot(xdata,ydata〔〕,logScaleFalse,dispTrue)fig。plot(xVals,yVals,)可以试试不显示logscale,y坐标值标尺为20000002百万一个刻度注意浏览器打开wbfig。wb() 4。2效果图: 5垂直柱状图column: 5。1代码:1组数据柱状图fromgpchartsimportfigurefigfigure()xdata〔1m,2m,3m,4m,5m〕ydata〔32,17,22,56,41〕fig。column(xdata,ydata)column垂直柱状图fig。wb()OK,wbwebbrowser2组数据柱状图fromgpchartsimportfigurefigfigure()xdata〔1m,2m,3m,4m,5m〕ydata〔〔32,17,22,56,41〕,〔22,44,35,22,37〕〕报错ydata〔〔32,22〕,〔17,44〕,〔22,35〕,〔56,22〕,〔41,37〕〕2组数据fig。column(xdata,ydata)column垂直柱状图fig。wb()OK,wbwebbrowser 5。2效果图: 6水平柱状图bar: 6。1代码:1组水平柱状图barfromgpchartsimportfigurefigfigure(PercentAlcoholConsumption)fig。bar(〔Percentage,Beer,Wine,Liquor〕,〔Type,40,50,10〕)fig。wb()2组水平柱状图barfromgpchartsimportfigurefigfigure(PercentAlcoholConsumption)xdata〔Percentage,Beer,Wine,Liquor〕ydata〔〔pig,dog〕,〔40,20〕,〔50,30〕,〔10,42〕〕fig。bar(xdataxdata,ydataydata)参数figure。bar(xdata,ydata,dispTrue)fig。wb() 6。2效果图: 7直方图hist: 7。1代码:fromgpchartsimportfigurehistogram直方图figfigure(Distribution,xlabelvalue)fig。hist(〔1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,4,4,5,6,7,8,8,8,8,8,9,9,9,10,11,12,13,13,13,13,14〕)等同于上面xdata〔1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,4,4,5,6,7,8,8,8,8,8,9,9,9,10,11,12,13,13,13,13,14〕fig。hist(xdataxdata)fig。wb() 7。2效果图: 注意:使用起来,非常方便,可惜支持图表类型有限。有机会可以在源代码的基础上进行修改,增加其他图形,那就更棒了。需要人维护,或者大神在其基础上增加代码。 比如在本机的这个位置的py文件,增加即可。 root下打开这个文件,进行修改 usrlocalpython3。8libpython3。8sitepackagesgpcharts。py 自己整理并分享出来 喜欢的就点赞、评论、转发、关注和收藏。