pyecharts Sankey()调整画布大小
时间: 2023-07-09 08:29:36 浏览: 154
要调整Pyecharts中Sankey图的画布大小,可以通过设置图表的宽度和高度来实现。例如,以下代码演示了如何将Sankey图的宽度设置为800像素,高度设置为600像素:
```python
from pyecharts import options as opts
from pyecharts.charts import Sankey
# 构造数据
nodes = [
{"name": "category1"},
{"name": "category2"},
{"name": "category3"},
{"name": "category4"},
{"name": "category5"},
]
links = [
{"source": "category1", "target": "category2", "value": 10},
{"source": "category2", "target": "category3", "value": 15},
{"source": "category3", "target": "category4", "value": 20},
{"source": "category4", "target": "category5", "value": 25},
]
# 绘制Sankey图
sankey = Sankey()
sankey.add("sankey", nodes, links)
sankey.set_global_opts(title_opts=opts.TitleOpts(title="Sankey图", subtitle="示例"))
sankey.set_series_opts(label_opts=opts.LabelOpts(font_size=12))
sankey.set_dimensions(width=800, height=600)
sankey.render("sankey.html")
```
在上面的代码中,我们通过调用`set_dimensions()`方法来设置Sankey图的宽度和高度。具体来说,我们将宽度设置为800像素,高度设置为600像素。您可以根据需要调整这些值。