Pyecharts
绘制一个柱状图
from pyecharts. faker import Faker
from pyecharts import options as opts
from pyecharts. charts import Bar
bar = Bar( )
bar. add_xaxis( [ "衬衫" , "毛衣" , "领带" , "裤子" , "风衣" , "高跟鞋" , "袜子" ] )
bar. add_yaxis( "商家A" , [ 114 , 55 , 27 , 101 , 125 , 27 , 105 ] )
bar. add_yaxis( "商家B" , [ 57 , 134 , 137 , 129 , 145 , 60 , 49 ] )
bar. set_global_opts( title_opts= opts. TitleOpts( title= "某商场销售情况" ) )
bar. render( 'this is a test html.html' )
堆叠柱状图
切换皮肤 旋转轴标签 stack堆叠 添加mark点, line辅助线 x轴y轴交换
from pyecharts. faker import Faker
from pyecharts import options as opts
from pyecharts. globals import ThemeType
from pyecharts. charts import Bar
bar = Bar( init_opts= opts. InitOpts(
theme= ThemeType. DARK,
width= '800px' ,
height= "600px" ) )
bar. add_xaxis( Faker. choose( ) )
bar. add_yaxis( '商家A' , Faker. values( ) , stack= 'stack1' )
bar. add_yaxis( '商家B' , Faker. values( ) , stack= 'stack1' )
bar. add_yaxis( '商家C' , Faker. values( ) , stack= 'stack2' )
bar. add_yaxis( '商家D' , Faker. values( ) , stack= 'stack2' )
bar. set_global_opts( title_opts= opts. TitleOpts( title= "Bar_基本示例" , subtitle= "我是副标题" ) ,
xaxis_opts= opts. AxisOpts( axislabel_opts= opts. LabelOpts( rotate= 30 ) ) )
bar. set_series_opts(
label_opts= opts. LabelOpts( is_show= False ) ,
markpoint_opts= opts. MarkPointOpts(
data= [
opts. MarkPointItem( type_= 'max' , name= "最大值" ) ,
opts. MarkPointItem( type_= 'min' , name= "最小值" ) ,
]
) ,
markline_opts= opts. MarkLineOpts(
data= [
opts. MarkLineItem( type_= "average" , name= "平均值" ) ,
]
)
)
bar. reversal_axis( )
bar. render( R'F:\1000篇技术博客\pyecharts\chart1.html' )
窗口滑块
from pyecharts. faker import Faker
from pyecharts import options as opts
from pyecharts. globals import ThemeType
from pyecharts. charts import Bar
bar = Bar( init_opts= opts. InitOpts(
theme= ThemeType. DARK,
width= '800px' ,
height= "600px" ) )
bar. add_xaxis( Faker. days_attrs)
bar. add_yaxis( "商家A" , Faker. days_values)
bar. set_global_opts(
title_opts= opts. TitleOpts(
title= "Bar_基本示例" ,
subtitle= "我是副标题" ) ,
datazoom_opts= [ opts. DataZoomOpts( ) ]
)
bar. render( R'F:\1000篇技术博客\pyecharts\chart1.html' )
3D柱状图
import random
from pyecharts. faker import Faker
from pyecharts import options as opts
from pyecharts. charts import Bar3D
bar3d = Bar3D( )
data = [ ( i, j, random. randint( 0 , 12 ) ) for i in range ( 24 ) for j in range ( 6 ) ]
bar3d. add(
"" ,
data,
xaxis3d_opts= opts. Axis3DOpts( Faker. clock, type_= 'category' ) ,
yaxis3d_opts= opts. Axis3DOpts( Faker. week_en, type_= 'category' ) ,
zaxis3d_opts= opts. Axis3DOpts( type_= 'value' ) ,
)
bar3d. set_global_opts(
visualmap_opts= opts. VisualMapOpts( max_= 20 ) ,
title_opts= opts. TitleOpts( title= "Bar3D_基本示例" )
)
bar3d. render( R'F:\1000篇技术博客\pyecharts\chart1.html' )
折线 / 面积图
from pyecharts. faker import Faker
from pyecharts import options as opts
from pyecharts. charts import Line
line = Line( )
line. add_xaxis( Faker. choose( ) )
line. add_yaxis( "商家A" , Faker. values( ) ,
is_smooth= True ,
areastyle_opts= opts. AreaStyleOpts(
opacity= 0.2 ,
color= '#000'
) )
line. add_yaxis( "商家B" , Faker. values( ) )
line. set_global_opts( title_opts= opts. TitleOpts( title= 'Line_基本示例' ) )
line. render( R'F:\1000篇技术博客\pyecharts\chart1.html' )
饼图
from pyecharts. faker import Faker
from pyecharts import options as opts
from pyecharts. charts import Pie
pie = Pie( )
pie. add( "" , [ list ( z) for z in zip ( Faker. choose( ) , Faker. values( ) ) ] ,
radius= [ "40%" , "75%" ] ,
rosetype= 'radius' )
pie. set_global_opts( title_opts= opts. TitleOpts( title= 'Pie_基本示例' ) )
pie. set_series_opts( label_opts= opts. LabelOpts( formatter= '{b}:{c}' ) )
pie. render( R'F:\1000篇技术博客\pyecharts\chart1.html' )
涟漪效果散点图
from pyecharts. faker import Faker
from pyecharts import options as opts
from pyecharts. charts import EffectScatter
from pyecharts. globals import SymbolType
effect_scatter = EffectScatter( )
effect_scatter. add_xaxis( Faker. choose( ) )
effect_scatter. add_yaxis( "" ,
Faker. values( ) ,
symbol= SymbolType. ARROW)
effect_scatter. set_global_opts( title_opts= opts. TitleOpts( title= "EffectScatter_基本示例" ) )
effect_scatter. render( R'F:\1000篇技术博客\pyecharts\chart1.html' )
漏斗图
from pyecharts. faker import Faker
from pyecharts import options as opts
from pyecharts. charts import Funnel
funnel = Funnel( )
funnel. add(
"用户转化率" ,
[ list ( z) for z in zip ( Faker. choose( ) , Faker. values( ) ) ] ,
label_opts= opts. LabelOpts( position= 'inside' )
)
funnel. set_global_opts( title_opts= opts. TitleOpts( title= "Funnel_基本示例" ) )
funnel. render( R'F:\1000篇技术博客\pyecharts\chart1.html' )
地理坐标系
from pyecharts. faker import Faker
from pyecharts import options as opts
from pyecharts. charts import Geo
geo = Geo( )
geo. add_schema( maptype= "china" )
geo. add( 'geo' , [ list ( z) for z in zip ( Faker. provinces, Faker. values( ) ) ] ,
type_= 'heatmap' )
geo. set_series_opts( label_opts= opts. LabelOpts( is_show= False ) )
geo. set_global_opts(
visualmap_opts= opts. VisualMapOpts( ) ,
title_opts= opts. TitleOpts( title= "Geo_基本示例" )
)
geo. render( R'F:\1000篇技术博客\pyecharts\chart1.html' )
水球图
from pyecharts import options as opts
from pyecharts. charts import Liquid
liquid = Liquid( )
liquid. add( 'Liquid' , [ 0.7 , 0.6 , 0.5 ] )
liquid. set_global_opts( title_opts= opts. TitleOpts( title= "Liquid_基本示例" ) )
liquid. render( R'F:\1000篇技术博客\pyecharts\chart1.html' )
雷达图
词云图