pyecharts官网,官网上基本模型的介绍都挺详细的,还有例子。
1、pyecharts基本演示
from pyecharts import options as opts
from pyecharts. charts import Pie
from pyecharts. faker import Faker
c = (
Pie( )
. add( "" , [ list ( z) for z in zip ( Faker. choose( ) , Faker. values( ) ) ] )
. set_colors( [ "blue" , "green" , "yellow" , "red" , "pink" , "orange" , "purple" ] )
. set_global_opts( title_opts= opts. TitleOpts( title= "Pie-设置颜色" ) )
. set_series_opts( label_opts= opts. LabelOpts( formatter= "{b}: {c}" ) )
. render( "pie_set_color.html" )
)
2、柱状图
from pyecharts import options as opts
from pyecharts. charts import Bar
from pyecharts. globals import ThemeType
"""
c = (
Bar() # 实例化柱状图的对象
.add_xaxis(["华东", "中南", "东北", "华北", "西南", "西北"]) # 增加x轴数据
# x轴数据 必须2个参数; series_name(指明数据的含义), y_axis(数据)
.add_yaxis(series_name="销售额", y_axis=[468, 413, 268, 244, 130, 81])
.render("销售数据可视化.html") # 输出图像;渲染图像
)
"""
bar = Bar(
init_opts= opts. InitOpts(
width= "1200px" ,
height= "500px" ,
bg_color= 'white' ,
)
)
bar. add_xaxis( [ "华东" , "中南" , "东北" , "华北" , "西南" , "西北" ] )
bar. add_yaxis( series_name= "销售额" , y_axis= [ 468 , 413 , 268 , 244 , 130 , 81 ] )
bar. add_yaxis( series_name= "销售数量" , y_axis= [ 200 , 300 , 350 , 210 , 170 , 150 ] )
bar. set_global_opts(
title_opts= opts. TitleOpts(
title= '各地区销售情况' ,
pos_left= 'center' ,
pos_top= "5%"
) ,
legend_opts= opts. LegendOpts(
pos_top= "10%"
) ,
toolbox_opts= opts. ToolboxOpts(
is_show= True ,
) ,
tooltip_opts= opts. TooltipOpts(
axis_pointer_type= "cross"
) ,
)
bar. reversal_axis( )
bar. set_series_opts( label_opts= opts. LabelOpts(
position= 'inside'
) )
bar. render( "销售数据可视化.html" )
3、饼图
from pyecharts import options as opts
from pyecharts. charts import Pie
label_name = [ "华北" , "东北" , "西南" ]
data = ( 200 , 210 , 380 )
data_pair = [ [ i, j] for i, j in zip ( label_name, data) ]
print ( data_pair)
pie = Pie( )
pie. add( series_name= "销售额" ,