正式发布python版本年份

首页 > 其他网络信息 > 作者:YD1662023-11-08 18:22:35

蝴蝶柱状图

两个不同类型的双排柱状图:

fromhighchartsimportHighchart H=Highchart(width=550,height=400) #1、数值分类区间 categories=['0-4','5-9','10-14','15-19', '20-24','25-29','30-34','35-39', '40-44','45-49','50-54','55-59', '60-64','65-69','70-74','75-79', '80-84','85-89','90-94','95-99','100 '] #2、配置项 #在这种图形中横轴和纵轴需要调换 options={ 'chart':{#指定图表类型:柱状图 'type':'bar' }, 'title':{#主标题 'text':'PopulationpyramidforGermany,midyear2010' }, 'subtitle':{#副标题 'text':'Source:www.census.gov' }, 'xAxis':[{#左侧标签设置 'categories':categories, 'reversed':False,#分类区间是否翻转 'labels':{ 'step':1#标签区间的间隔 } },{#右侧标签设置 'opposite':True, 'reversed':False, 'categories':categories, 'linkedTo':0, 'labels':{ 'step':1 } }], 'yAxis':{ 'title':{ 'text':None }, 'labels':{#y轴标签 'formatter':"function(){\ return(Math.abs(this.value)/1000000) 'M';\ }" }, 'min':-4000000, 'max':4000000 }, 'plotOptions':{ 'series':{ 'stacking':'normal' } }, 'tooltip':{ 'formatter':"function(){\ return'<b>' this.series.name ',age' this.point.category '</b><br/>' \ 'Population:' Highcharts.numberFormat(Math.abs(this.point.y),0);\ }" }, } #设置男女的数值 data_male=[-1746181,-1884428,-2089758,-2222362, -2537431,-2507081,-2443179,-2664537, -3556505,-3680231,-3143062,-2721122, -2229181,-2227768,-2176300,-1329968, -836804,-354784,-90569,-28367,-3878] data_female=[1656154,1787564,1981671,2108575, 2403438,2366003,2301402,2519874, 3360596,3493473,3050775,2759560, 2304444,2426504,2568938,1785638, 1447162,1005011,330870,130632,21208] #添加配置项 H.set_dict_options(options) #添加数据和指定图表类型bar H.add_data_set(data_male,'bar','Male') H.add_data_set(data_female,'bar','Female') H

正式发布python版本年份,(9)

垂直柱状图

fromhighchartsimportHighchart#导入库 H=Highchart(width=800,height=600)#设置图形的大小 #配置数据项 data1=[5,3,4,7,2] data2=[2,2,3,2,1] data3=[3,4,4,2,5] options={ 'chart':{ 'type':'column'#bar改成column }, 'title':{ 'text':'Stackedcolumnchart' }, 'xAxis':{ 'categories':['Apples','Oranges','Pears','Grapes','Bananas'] }, 'yAxis':{ 'min':0, 'title':{ 'text':'Totalfruitconsumption' }, 'stackLabels':{ 'enabled':True, 'style':{ 'fontWeight':'bold', 'color':"(Highcharts.defaultOptions.title.style&&\ Highcharts.defaultOptions.title.style.color)||'gray'" } } }, 'legend':{ 'align':'right', 'x':-30, 'verticalAlign':'top', 'y':25, 'floating':True, 'backgroundColor': "Highcharts.defaultOptions.legend.backgroundColor||'white'", 'borderColor':'#CCC', 'borderWidth':1, 'shadow':False }, 'tooltip':{ 'headerFormat':'<b>{point.x}</b><br/>', 'pointFormat':'{series.name}:{point.y}<br/>Total:{point.stackTotal}' }, #在这里设置堆叠的信息 'plotOptions':{#将每个数据在柱状图上方显示出来 'column':{ 'stacking':'normal', 'dataLabels':{ 'enabled':True#显示数据(柱状图顶部的数据显示出来) } } } } H.set_dict_options(options)#添加配置 #将之前的bar改成column即可 H.add_data_set(data1,'column','John') H.add_data_set(data2,'column','Jane') H.add_data_set(data3,'column','Joe') H

正式发布python版本年份,(10)

水平叠加柱状图

fromhighchartsimportHighchart#导入库 H=Highchart(width=800,height=600)#设置图形的大小 #配置数据项 data1=[5,3,4,7,2] data2=[2,2,3,2,1] data3=[3,4,4,2,5] options={ 'chart':{ 'type':'bar'#图表类型 }, 'title':{#主标题 'text':'Stackedbarchart' }, 'xAxis':{ 'categories':['Apples','Oranges','Pears','Grapes','Bananas'] }, 'yAxis':{ 'min':0, 'title':{ 'text':'Totalfruitconsumption' } }, 'legend':{ 'reversed':True }, 'plotOptions':{ 'series':{ 'stacking':'normal' } } } H.set_dict_options(options)#添加配置 H.add_data_set(data1,'bar','John') H.add_data_set(data2,'bar','Jane') H.add_data_set(data3,'bar','Joe') H

正式发布python版本年份,(11)

带有负值的柱状图

有时候我们的数据中还有负值,利用Highcharts同样可以绘制柱状图:

fromhighchartsimportHighchart#导入库 H=Highchart(width=800,height=600)#设置图形的大小 #配置数据项 data1=[5,3,-4,7,2] data2=[2,2,3,-2,1] data3=[-3,4,4,2,5] options={ 'chart':{#图表类型不是bar,而是column 'type':'column' }, 'title':{#主标题 'text':'columnwithnegativevalues' }, 'xAxis':{ 'categories':['Apples','Oranges','Pears','Grapes','Bananas'] }, 'yAxis':{ 'title':{ 'text':'水果数量',#y轴名称 'align':'high' }, 'labels':{ 'overflow':'justify' } }, 'legend':{ 'reversed':True }, 'credits':{#右下角的版权信息 'enabled':False }, 'plotOptions':{#将每个数据在柱状图上方显示出来 'bar':{ 'dataLabels':{ 'enabled':True#显示数据(柱状图顶部的数据显示出来) } } } } H.set_dict_options(options)#添加配置 H.add_data_set(data1,'bar','John') H.add_data_set(data2,'bar','Jane') H.add_data_set(data3,'bar','Joe') H

正式发布python版本年份,(12)

上一页12345下一页

栏目热文

文档排行

本站推荐

Copyright © 2018 - 2021 www.yd166.com., All Rights Reserved.