在 Google Colab 中显示 igraph 图
Show igraph plots in Google Colab
我正在尝试在 Google Colab 中绘制 igraph
绘图,但无法正常工作。
我正在使用以下代码绘制图表:
fg = Graph.Full(n=40, directed=False, loops=False)
plot(fg).show()
起初我遇到了这个错误 "NotImplementedError: showing plots is not implemented on this platform: Linux"
但我能够通过使用以下配置图像查看器来解决这个问题:
from igraph import Configuration
cfg = Configuration.instance()
cfg['apps.image_viewer'] = "eog"
这消除了错误,但仍然没有显示任何图像。
删除 show()
语句以内联显示也不起作用。
有没有一种方法可以在 Google Colab 中绘制 igraph 图,或者它只是不兼容?
感谢您的帮助。
.show()
方法已弃用,将在未来版本中删除。不要使用它。有关详细信息,请参阅文档字符串。只需使用 plot(g)
.
您可以使用
在 Google Colab 上安装 igraph
!pip install igraph
要使用绘图,您有两种选择。
使用开罗后端:
安装pycairo
,
!apt install libcairo2-dev
!pip install pycairo
import igraph as ig
g = ig.Graph.Erdos_Renyi(n=100, m=200)
ig.plot(g)
使用实验性 matplotlib 后端(功能尚未完成):
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ig.plot(g, target=ax)
或更短:
ig.plot(g, target=plt.axes())
我正在尝试在 Google Colab 中绘制 igraph
绘图,但无法正常工作。
我正在使用以下代码绘制图表:
fg = Graph.Full(n=40, directed=False, loops=False)
plot(fg).show()
起初我遇到了这个错误 "NotImplementedError: showing plots is not implemented on this platform: Linux"
但我能够通过使用以下配置图像查看器来解决这个问题:
from igraph import Configuration
cfg = Configuration.instance()
cfg['apps.image_viewer'] = "eog"
这消除了错误,但仍然没有显示任何图像。
删除 show()
语句以内联显示也不起作用。
有没有一种方法可以在 Google Colab 中绘制 igraph 图,或者它只是不兼容?
感谢您的帮助。
.show()
方法已弃用,将在未来版本中删除。不要使用它。有关详细信息,请参阅文档字符串。只需使用 plot(g)
.
您可以使用
在 Google Colab 上安装 igraph!pip install igraph
要使用绘图,您有两种选择。
使用开罗后端:
安装pycairo
,
!apt install libcairo2-dev
!pip install pycairo
import igraph as ig
g = ig.Graph.Erdos_Renyi(n=100, m=200)
ig.plot(g)
使用实验性 matplotlib 后端(功能尚未完成):
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ig.plot(g, target=ax)
或更短:
ig.plot(g, target=plt.axes())