使用Appexchart库,可以将气泡图和折线图组合在一起。以下是使用Appexchart库创建组合图的示例代码:
import appexchart as aec
# 创建气泡图数据
bubble_data = [['USA', 34, 78, 1000], ['China', 44, 60, 1200], ['India', 20, 40, 500], ['Brazil', 60, 20, 800]]
bubble_settings = {
'type': 'bubble',
'x_scale': 1,
'y_scale': 1,
}
# 创建折线图数据
line_data = [['USA', 32, 42], ['China', 38, 50], ['India', 25, 30], ['Brazil', 55, 15]]
line_settings = {
'type': 'line',
'y_axis': 'right',
'line_width': 3,
'line_style': 'dashed',
'legend_title': 'Legend for Line Chart',
}
# 设定图表标题和x轴标题
chart_title = 'Combined Bubble and Line Chart'
x_axis_title = 'X Axis Label'
# 组合气泡图和折线图
chart_settings = {
'title': chart_title,
'x_axis_title': x_axis_title,
'x_scale': 1,
'y_scale': 1,
'y_axis_right': line_settings,
'chart_data': [bubble_settings, line_settings],
}
# 生成图表并输出
html = aec.chart(chart_settings, bubble_data, line_data)
print(html)
以上代码将在页面上生成组合图,其中左侧为气泡图,右侧为折线图。