How can I enable `cairo` backend while plotting `igraph` objects on matplotlib?

馋奶兔 提交于 2021-02-11 13:29:56

问题


I'm using Jupyter Notebook and trying to make graphs of igraph appear on matplotlib plots. I've found that one of possible solutions is to create GraphArtist class class that draws igraph graphs but, unfortunately, only Cairo-based backends are supported. When I try to use it, no plot is displayed

import matplotlib
matplotlib.use("cairo")
fig = plt.figure()
ax = plt.gca()
plt.plot(range(10), [i**1.5 for i in range(10)]) #a simplified version of my diagram
plt.show()

and I get this warning:

UserWarning: Matplotlib is currently using cairo, which is a non-GUI backend, so cannot show the figure.

And, indeed, I can see that it's not on the list:

>>> print ("Non Gui backends are:", matplotlib.rcsetup.non_interactive_bk)
>>> print ("Gui backends are", matplotlib.rcsetup.interactive_bk)
Non Gui backends are: ['agg', 'cairo', 'pdf', 'pgf', 'ps', 'svg', 'template']
Gui backends are: ['GTK3Agg', 'GTK3Cairo', 'MacOSX', 'nbAgg', 'Qt4Agg', 'Qt4Cairo', 'Qt5Agg', 'Qt5Cairo', 'TkAgg', 'TkCairo', 'WebAgg', 'WX', 'WXAgg', 'WXCairo']

What can I do to enable this cairo backend? Additional question: there is matplotlib.use("cairo.pdf") used in a link, can it affect an output of script there?

来源:https://stackoverflow.com/questions/63536495/how-can-i-enable-cairo-backend-while-plotting-igraph-objects-on-matplotlib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!