from pyecharts. charts import Line
from pyecharts import options as opts
from pyecharts. faker import Faker
from pyecharts. globals import ThemeType
from pyecharts. globals import CurrentConfig, NotebookType
CurrentConfig. NOTEBOOK_TYPE = NotebookType. JUPYTER_LAB
c= (
Line( )
. add_xaxis( Faker. choose( ) )
. add_yaxis( '商家A' , Faker. values( ) )
. add_yaxis( '商家B' , Faker. values( ) , is_smooth= True )
. set_global_opts(
title_opts= opts. TitleOpts( title= '折线图' ) ,
tooltip_opts= opts. TooltipOpts( trigger= 'axis' )
)
)
c. render_notebook( )
细节描绘 折线图
c= (
Line(
init_opts= opts. InitOpts(
width= '800px' ,
height= '500px'
)
)
. add_xaxis( xaxis_data= Faker. week)
. add_yaxis(
'商家A' ,
y_axis= [ 120 , 200 , 150 , 250 , 42 , 551 , 421 ] ,
symbol= 'triangle' ,
symbol_size= 20 ,
linestyle_opts= opts. LineStyleOpts(
color= 'green' ,
width= 2 ,
type_= 'dashed'
) ,
label_opts= opts. LabelOpts( is_show= False ) ,
itemstyle_opts= opts. ItemStyleOpts(
border_width= 2 ,
border_color= 'yellow' ,
color= 'blue' ,
) ,
markpoint_opts= opts. MarkPointOpts(
data= [
opts. MarkPointItem( type_= 'max' ) ,
opts. MarkPointItem( type_= 'min' ) ,
]
) ,
markline_opts= opts. MarkLineOpts(
data= [
opts. MarkLineItem( type_= 'average' ) ,
]
)
)
. set_global_opts(
yaxis_opts= opts. AxisOpts(
type_= 'value' ,
splitarea_opts= opts. SplitLineOpts( is_show= True )
) ,
tooltip_opts= opts. TooltipOpts( trigger= 'axis' )
)
)
c. render_notebook( )
面积图
x_data= [ '周一' , '周二' , '周三' , '周四' , '周五' , '周六' , '周日' ]
y_data= [ 820 , 932 , 901 , 934 , 1290 , 1330 , 1320 ]
c = (
Line( )
. add_xaxis( xaxis_data= x_data)
. add_yaxis(
'' ,
y_axis= y_data,
areastyle_opts= opts. AreaStyleOpts( opacity= 0.8 ) )
. set_global_opts(
title_opts= opts. TitleOpts( title= '面积图' ) ,
tooltip_opts= opts. TooltipOpts( trigger= 'axis' ) ,
xaxis_opts= opts. AxisOpts( type_= 'category' , boundary_gap= False )
)
)
c. render_notebook( )
堆叠面积图
c = (
Line( )
. add_xaxis( xaxis_data= x_data)
. add_yaxis(
'广告' ,
stack= '堆叠' ,
y_axis= [ 120 , 40 , 60 , 50 , 45 , 65 , 84 ] ,
areastyle_opts= opts. AreaStyleOpts( opacity= 0.8 ) ,
label_opts= opts. LabelOpts( is_show= False )
)
. add_yaxis(
'销售' ,
stack= '堆叠' ,
y_axis= [ 120 , 40 , 60 , 50 , 45 , 65 , 84 ] ,
areastyle_opts= opts. AreaStyleOpts( opacity= 0.8 ) ,
label_opts= opts. LabelOpts( is_show= False )
)
. add_yaxis(
'浏览' ,
stack= '堆叠' ,
y_axis= [ 120 , 40 , 60 , 50 , 45 , 65 , 84 ] ,
areastyle_opts= opts. AreaStyleOpts( opacity= 0.8 ) ,
label_opts= opts. LabelOpts( is_show= False )
)
. set_global_opts(
title_opts= opts. TitleOpts( title= '堆叠面积图' ) ,
tooltip_opts= opts. TooltipOpts( trigger= 'axis' ) ,
xaxis_opts= opts. AxisOpts( type_= 'category' , boundary_gap= False )
)
)
c. render_notebook( )