
原始碼如下:
from pyecharts.charts import Bar,Line
from pyecharts import options as opts
fushi=["襯衫", "毛衣", "領帶", "褲子", "風衣", "高跟鞋", "襪子"]
A= [114, 55, 27, 101, 125, 27, 105]
B= [57, 134, 137, 129, 145, 60, 49]
def bar_charts()->Bar:
bar1 = (
Bar(init_opts=opts.InitOpts(width='1000px',height='500px')) # 示例物件
.add_xaxis(fushi) # x軸資料
.add_yaxis("商家A",A) # 圖例名稱 + y軸資料
.add_yaxis("商家B",B)
# 全域配置:標題/副標題
.set_global_opts(title_opts=opts.TitleOpts(title="商場銷售情況1"),
tooltip_opts=opts.TooltipOpts(trigger='axis',axis_pointer_type='cross'), # 指示器型別,十字/陰影/直線/無
toolbox_opts=opts.ToolboxOpts(
is_show = True, ))
# bar 拓展
.extend_axis(
yaxis=opts.AxisOpts( # 右側y軸標簽
name='價格',
type_='value', # 型別
min_=0,
max_=100,
interval=10, # 間隔
axislabel_opts=opts.LabelOpts(formatter='{value}元') # 標簽顯示
)
)
)
return bar1
y=[36,87,75,48,32,86,25]
def line_charts()->Line():
line1=(
Line()
.add_xaxis(fushi)
.add_yaxis('price',y,yaxis_index=1, # 線圖用右側索引,因此為1
label_opts=opts.LabelOpts(is_show=True),is_smooth=True)
)
return line1
bar1=bar_charts()
line1=line_charts()
# line1.render_notebook()
bar1.overlap(line1).render_notebook()
求大神幫我解答一下~謝謝~
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/95157.html
