用Holoviews构建和弦图:没有错误,但是没有保存图像

2024-06-28 10:59:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我想画一个和弦图。为了首先使该方法工作,我遵循this示例。(请注意,为此,您必须在命令行中键入'bokeh sampledata'以下载示例数据)。在

我使用的代码(主要取自示例,但添加matplotlib来保存图像)是:

import holoviews as hv
from holoviews import opts, dim
from bokeh.sampledata.airport_routes import routes, airports
hv.extension('bokeh')

# Count the routes between Airports
route_counts = routes.groupby(['SourceID', 'DestinationID']).Stops.count().reset_index()
nodes = hv.dataset(airports, 'AirportID', 'City')
chord = hv.Chord((route_counts, nodes), ['SourceID', 'DestinationID'], ['Stops'])

# Select the 20 busiest airports
busiest = list(routes.groupby('SourceID').count().sort_values('Stops').iloc[-20:].index.values)
busiest_airports = chord.select(AirportID=busiest, selection_mode='nodes')

fig = plt.figure()
busiest_airports.opts(opts.Chord(cmap='Category20', edge_color=dim('SourceID').str(),height=800, labels='City', node_color=dim('AirportID').str(), width=800))
fig.savefig('plot.png')

有一个文件叫做绘图.png制造了,但它是空的。我尝试过用不同的方式编辑代码(例如,使用不同的图像格式,如.pdf),但它没有改变。有人有什么想法吗?在

更新工作原理: 导入全息视图为hv 从holoviews导入opts,dim 从bokeh.sampledata.airport_路线进口航线、机场 高压扩展('bokeh')

^{pr2}$

正如下面建议的那样,它是有效的。在


Tags: import示例bokehholoviewsnodeshvdimroutes