pyecharts怎么在同一个html中并行显示两个图
时间: 2024-09-23 18:08:59 浏览: 155
在PyEcharts中,要在同一个HTML文件中并排显示两个或更多的图表,你需要先创建每个图表实例,然后将它们添加到同一个Div容器中。下面是一个简单的例子,展示如何在同一页面上并排显示两个柱状图:
```python
from pyecharts import options as opts
from pyecharts.charts import Bar
# 图表一
bar1 = Bar().add_xaxis(["A", "B", "C", "D", "E"]).add_yaxis("Series1", [5, 20, 36, 10, 15])
bar1.render_to_html('chart1_div', width=400, height=300) # 设置宽度和高度
# 图表二
bar2 = Bar().add_xaxis(["F", "G", "H", "I", "J"]).add_yaxis("Series2", [15, 10, 25, 5, 20])
bar2.render_to_html('chart2_div', width=400, height=300, container='container') # 容器名称
# 将两个图表放在同一个div容器中
container = '''
<div style="width: 800px; height: 600px;">
<div id="chart1_div" style="float:left;"></div>
<div id="chart2_div" style="float:right;"></div>
</div>
'''
with open('output.html', 'w', encoding='utf-8') as f:
f.write(container)
```
这将在名为`output.html`的文件中生成一个包含两个并排柱状图的HTML页面。你可以根据需要更改宽度、高度以及图表的内容。
阅读全文
相关推荐














