①绘制雷达图:
from pyecharts.charts import Radarfrom pyecharts import options as optsradar_data1 = [[4300, 10000, 28000, 35000, 50000, 19000]]radar_data2 = [[5000, 14000, 28000, 31000, 42000, 21000]]radar = (Radar().add_schema(schema=[opts.RadarIndicatorItem(name="维护", max_=6500),opts.RadarIndicatorItem(name="管理", max_=16000),opts.RadarIndicatorItem(name="广告投入", max_=30000),opts.RadarIndicatorItem(name="客服", max_=38000),opts.RadarIndicatorItem(name="人力", max_=52000),opts.RadarIndicatorItem(name="研发", max_=25000)],splitarea_opt=opts.SplitAreaOpts(is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1))).add(series_name="预算经费",data=radar_data1,).add(series_name="实际开销",data=radar_data2,linestyle_opts=opts.LineStyleOpts(color="#1c86ee")))radar.render("雷达图.html")
该例通过Radar来定义图表类型为雷达图,schema用于定义雷达各维度的范围大小;radar. add()用于定义雷达图上的文字,以便于区分。
运行结果:
②绘制折线图:
1.绘制最大值折线图
from pyecharts.charts import Linefrom pyecharts import options as optsattr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]v1 = [25, 24, 36, 10, 90, 100]line = (Line().add_xaxis(attr).add_yaxis('商家A', v1,markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_='max')])).set_global_opts(title_opts=opts.TitleOpts(title="折线图")))line.render("最大值折线图.html")
该例通过Line来定义图表类型为折线图,attr定义横轴,v1定义纵轴。
.add_yaxis('商家A', v1,markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_='max')]))
定义高亮显示最大值。
.set_global_opts(title_opts=opts.TitleOpts(title="折线图"))
定义图例名称。
运行结果:
2.绘制平均值折线图
from pyecharts.charts import Linefrom pyecharts import options as optsattr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]v1 = [25, 24, 36, 10, 90, 100]v2 = [35, 64, 16, 60, 100, 50]line = (Line().add_xaxis(attr).add_yaxis('商家A', v1,markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_='max')])).add_yaxis('商家B', v2,markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_='average')])).set_global_opts(title_opts=opts.TitleOpts(title="折线图")))line.render("平均值折线图.html")
markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_='average')])
表示显示平均值。
运行结果:
③绘制面积图:
from pyecharts.charts import Linefrom pyecharts import options as optsattr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]v1 = [25, 24, 36, 10, 90, 100]v2 = [35, 64, 16, 60, 100, 50]line = (Line().add_xaxis(attr).add_yaxis('商家A', v1, areastyle_opts=opts.AreaStyleOpts(opacity=0.5)).add_yaxis('商家B', v2, is_smooth=True, areastyle_opts=opts.AreaStyleOpts(opacity=0.5)).set_global_opts(title_opts=opts.TitleOpts(title="面积图")))line.render("面积图.html")
v1, areastyle_opts=opts.AreaStyleOpts(opacity=0.5)
设置区域的透明度;
is_smooth=True
将折线以较圆滑的方式来呈现。
运行结果: