# 【组合图表:并行多图】
# 组合图表,也是一种特殊的图表类型
# 并行多图: 就是往组合图表里面填充各种图表(Bar,Line,Scatter) —— 往图表里面填充图表
# 1.创建一个Grid图表
# 2.往Grid图表里面填充其他图表(Bar,Line,Scatter)
from pyecharts import options as opts
from pyecharts.charts import Bar, Grid, Line,Pie,Radar
x_data = ["2014", "2015", "2016", "2017", "2018", "2019", "2020", "2021"]
bar1 = (
Bar()
.add_xaxis(xaxis_data=x_data)# 导入系列数据
.add_yaxis(
series_name="诊疗量(万人次)",# 系列名称,用于 tooltip 的显示,legend 的图例筛选。
y_axis=[87430,90912,96225,101885,107147,116390,105764,120215],# 系列数据
label_opts=opts.LabelOpts(is_show=False), # 是否显示数据标签
)
.extend_axis(
yaxis=opts.AxisOpts( #新增 Y 坐标轴配置项
name="同比增速(%)", #新增 Y 坐标名字
type_="value", # 'value': 数值轴,适用于连续数据。
min_=-20, #坐标轴最小值
max_=15, #坐标轴最大值,#LabelOpts:标签配置项
)
)
.set_global_opts( #全局配置项可通过 set_global_opts 方法设置
tooltip_opts=opts.TooltipOpts( #TooltipOpts:提示框配置项
is_show=True, trigger="axis", axis_pointer_type="cross" #is_show是否显示,trigger坐标轴触发,指示器类型:十字准星
),
xaxis_opts=opts.AxisOpts(
type_="category",
axispointer_opts=opts.AxisPointerOpts(is_show=True, type_="shadow"),
),
yaxis_opts=opts.AxisOpts(
name="诊疗量(万人次)",
type_="value",
min_=0,
max_=150000,
axislabel_opts=opts.LabelOpts(formatter="{value} ml"),
axistick_opts=opts.AxisTickOpts(is_show=True),
splitline_opts=opts.SplitLineOpts(is_show=True),
),
title_opts=opts.TitleOpts(title='2014-2021年中国中医类医疗卫生机构诊疗量'),
legend_opts=opts.LegendOpts(pos_left='45%' ),# 图例组件离容器左侧的距离45%。
)
.set_series_opts( #系统配置项
itemstyle_opts=opts.ItemStyleOpts(
opacity=0.5))#柱状图透明度
)
line1 = (
Line()
.add_xaxis(xaxis_data=x_data)
.add_yaxis(
series_name="同比增速(%)",
yaxis_index=1,#在单个图表实例中存在多个 y 轴的时候有用。这里就是用于第一个y轴
y_axis=[7.40,4.00,5.83,5.81,5.16,8.63,-9.13,13.66],#数据
)
.set_global_opts(
title_opts=opts.TitleOpts(title="同比增速", pos_top="10%"),
legend_opts=opts.LegendOpts(pos_top="10%"),
)
)
data = [['20岁以下-2.2%', 2.2], ['20-30岁-27.9%', 27.9], ['31-40岁-56.2%', 56.2], ['41-50岁-10.9%', 10.9],['50岁以上-2.8%',2.8]]#饼图数据
pie = (
Pie()
.add("",data,
is_avoid_label_overlap = False,
percent_precision = 2,
radius=["12.5%", "25%"],
center=["16.5%","60%"]
)
.set_global_opts(
title_opts=opts.TitleOpts(title="中药材消费者画像", pos_top="40%"),
legend_opts=opts.LegendOpts(pos_top="45%",pos_left='1%',is_show = False),
)
)
data2 = ['2019年','2020年','2021年','2022年','2023年']
bar2 = (
Bar()
.add_xaxis(xaxis_data=data2)
.add_yaxis(
series_name="跨国企业占比",
y_axis=[20.3,22.0,23.5,22.5,22.3],stack="stack1", category_gap="50%",xaxis_index=1,yaxis_index=2
)
.add_yaxis(
series_name="本土企业占比",
y_axis=[79.7,78.0,76.5,77.5,77.7],stack="stack1", category_gap="50%",xaxis_index=1,yaxis_index=2)
.set_global_opts(
title_opts=opts.TitleOpts(title="全国药店饮片供应商占比",pos_top="40%",pos_left="40%"),
legend_opts=opts.LegendOpts(is_show=False),
)
)
radar_data=['化学药','中成药','生物制品','医疗器械','中药饮片','保健品']
data2 = [[50,45,3,9,6,4]]
# radar = (
# Radar()
# .add_schema(schema=[opts.RadarIndicatorItem(name="化学药", max_=50),
# opts.RadarIndicatorItem(name="中成药", max_=50),
# opts.RadarIndicatorItem(name="生物制品", max_=50),
# opts.RadarIndicatorItem(name="医疗器械", max_=50),
# opts.RadarIndicatorItem(name="中药饮片", max_=50),
# opts.RadarIndicatorItem(name="保健品", max_=50),],shape="circle",
# splitarea_opt=opts.SplitAreaOpts(
# is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)
# ))
# .add(
# series_name="中成药",
# data=data2,
# linestyle_opts=opts.LineStyleOpts(color="#CD0000"),
# )
# .add(
# series_name='化学药',
# data=data2,
# linestyle_opts=opts.LineStyleOpts(color="#5CACEE"),
# )
# .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
# .set_global_opts(
# title_opts=opts.TitleOpts(title="全国药店药品销售额占比",pos_top="1%",pos_left="40%"),legend_opts=opts.LegendOpts()
# )
# )
overlap_1 = bar1.overlap(line1)
grid = (
# 1.创建一个Grid图表
Grid(init_opts=opts.InitOpts(width="1000px", height="800px"))
# 2.往Grid图表里面填充其他图表(Bar,Line,Scatter)
# 通过联合调整pos_bottom, pos_top, pos_left, pos_right这四个参数,可以精细布局图表在整张画布中的位置
.add(overlap_1, grid_opts=opts.GridOpts(pos_bottom='70%',pos_top="10%",
pos_left="10%",pos_right="10%",
),is_control_axis_index=True)
.add(bar2, grid_opts=opts.GridOpts(is_show=True,pos_bottom=450, pos_top=600, pos_left="40%", pos_right="40%"),is_control_axis_index=True)
.add(pie, grid_opts=opts.GridOpts(pos_bottom=40, pos_top=400, pos_left="10%", pos_right="70%"))
#add(radar, grid_opts=opts.GridOpts(pos_bottom="1%",pos_top="70%",pos_left="80%",pos_right="1%",))
)
grid.render_notebook()
pyecharts的并行多图
最新推荐文章于 2023-12-22 13:17:20 发布