1说明: 1。1HoloViews是PyViz的产品之一,而且其提供了Bokeh,matplotlib和Datashader可视化库的扩展。 1。2HoloViews库用来制作数据可视化,比bokeh和matplotlib更方便、更简洁,是一个python库文件。 1。3基于jupyter的可交互的,当然还可以生成html和svg等格式。 1。4目前国内中文教程基本没有,我来介绍一下。 2准备: 2。1官网:https:github。comholovizholoviewshttps:holoviews。orghttps:holoviews。orggalleryindex。html 2。2安装:pipinstallholoviews本机安装sudopip3。8installholoviews 2。3环境: 华为笔记本电脑、深度deepinlinux操作系统、谷歌浏览器、python3。8和微软vscode编辑器。 3散点图: 3。1基本散点图: 3。1。1代码:注意是一个单元cell基本散点图importholoviewsashvfromholoviewsimportoptshv。extension(bokeh)hv。extension(matplotlib)不是随便这样就可以切换matplotlib的x〔a,b,c,d,e,f,g,h〕y〔50,40,65,10,25,37,80,60〕scatterhv。Scatter((x,y))overlayscatter。opts(设置散点大小、填充颜色和圆边线颜色,图标fig的大小opts。Scatter(size15,fillcolororange,linecolorgreen,width400,height400),)overlay保存文件hv。save(overlay,filenamehomexgjDesktopholoviews12scatter1。html) 3。1。2操作和效果图: 3。2垂直气球图: 3。2。1代码:垂直气球图SpikesScatterimportholoviewsashvfromholoviewsimportoptshv。extension(bokeh)x〔a,b,c,d,e,f,g,h〕y〔50,40,65,10,25,37,80,60〕scatterhv。Scatter((x,y))spikeshv。Spikes(scatter)overlay(spikesscatter)。opts(opts。Scatter(size15,fillcolororange,linecolorgreen,width400,height400),)overlayjupyter显示保存文件hv。save(overlay,filenamehomexgjDesktopholoviews13scatter2。html) 3。2。2图: 3。3水平气球图: 3。3。1代码:importholoviewsashvfromholoviewsimportoptshv。extension(bokeh)x〔a,b,c,d,e,f,g,h〕y〔50,40,65,10,25,37,80,60〕scatterhv。Scatter((x,y))spikeshv。Spikes(scatter)overlay(spikesscatter)。opts(opts。Scatter(size15,fillcolororange,linecolorgreen,width400,height400),设置杆,变成水平杆和相关定义opts。Spikes(colorgreen,linewidth4,labelled〔〕,invertaxesTrue,colorindexNone),)保存文件hv。save(overlay,filenamehomexgjDesktopholoviews13scatter3。html) 3。3。2图: 3。4组合复合图: heatmap(热力图)spikesScatter(水平气球图) 3。4。1代码:importholoviewsashvfromholoviewsimportoptshv。extension(bokeh)散点图数据factors〔a,b,c,d,e,f,g,h〕x〔50,40,65,10,25,37,80,60〕scatterhv。Scatter((factors,x))spikeshv。Spikes(scatter)热力图数据x〔foo,foo,foo,bar,bar,bar,baz,baz,baz〕y〔foo,bar,baz,foo,bar,baz,foo,bar,baz〕z〔0,1,2,3,4,5,6,7,8〕heatmaphv。HeatMap((x,y,z))组合overlay(heatmapspikesscatter)。opts(opts。Scatter(size15,fillcolororange,linecolorgreen),opts。Spikes(colorgreen,linewidth4,labelled〔〕,invertaxesTrue,colorindexNone),opts。Layout(sharedaxesFalse))保存文件,指定目录和文件夹hv。save(overlay,filenamehomexgjDesktopholoviews6heatmapscatter。html) 3。4。2图: 4面积图area: 4。1代码:importnumpyasnpimportholoviewsashvfromholoviewsimportopts基于bokehhv。extension(bokeh)模拟数据pythonnp。array(〔2,3,7,5,26,221,44,233,254,265,266,267,120,111〕)JavaScriptnp。array(〔12,33,47,15,126,121,144,233,254,225,226,267,110,130〕)htmlnp。array(〔22,43,10,25,26,101,114,203,194,215,201,227,139,160〕)x坐标是kdims,y坐标是vdimsdimsdict(kdimstime,vdimsmemory)pythonhv。Area(python,labelpython,dims)JavaScripthv。Area(JavaScript,labelJavaScript,dims)htmlhv。Area(html,labelhtml,dims)在opts中的opts的Area中可设置图标fig的大小默认估计是200和200,比较小opts。defaults(opts。Area(fillalpha0。5,width400,height400))overlay(pythonJavaScripthtml)图表的标题名overlay。relabel(AreaChart)保存文件hv。save(overlay,filenamehomexgjDesktopholoviews1area。html) 4。2图: 5curve曲线图: 5。1代码:curve曲线图importholoviewsashvfromholoviewsimportoptshv。extension(bokeh)模拟数据stamp〔。33,。33,。34,。37,。37,。37,。37,。39,。41,。42,。44,。44,。44,。45,。46,。49,。49〕postcard〔。20,。20,。21,。23,。23,。23,。23,。24,。26,。27,。28,。28,。29,。32,。33,。34,。35〕标题名groupU。S。PostageRates(19992015)曲线图设置stamphv。Curve(stamp,vdimsRateperounce,labelstamp,groupgroup)postcardhv。Curve(postcard,vdimsRateperounce,labelpostcard,groupgroup)postage(stamppostcard)postage。opts(曲线图设置,大小和样式opts。Curve(interpolationstepsmid,width400,height400,linedashhv。Cycle(values〔dashed,solid〕)),图例位置opts。Overlay(legendpositiontopleft))hv。save(postage,filenamehomexgjDesktopholoviews2curve。html) 5。2图: 附注3张高级图,代码省略。 自己整理并分享出来 喜欢的人,请点赞、关注、评论、转发和收藏。 要是喜欢的人多了,以后有机会出教程。