Annotating graph-tool graphs with graph_draw as a matplotlib subplot?
I'm trying to annotate a graph plot with associated data and analysis. To do this, I'd like to use graph_plot as a subplot within a matplotlib graphic, ideally inline within a Jupyter notebook and "%matplotlib inline". Inline graph_plot works great by itself within Jupyter, but the graphs lack annotation or related content within the same output cell. Is there a way to get a graph_plot as a subplot within a matplotlib object? Or some equivalent approach that would allow for general graphical annotations of graph-tool graph plots? -- View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/... Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com.
Thank you Tiago and feliz Ano Novo. I hope I'm not getting greedy here, but I'd like to get this inline within a Jupyter Notebook. I have graph_draw(mplfig=) working outside of a Jupyter notebook, and graph_draw itself works great inline within a Jupyter notebook. It should be possible to get both together to produce nice annotations of graphs in a notebook. Based on this Stackoverflow thread <http://stackoverflow.com/questions/34425955/make-coordinate-systems-agree-between-matplotlib-and-graph-tool> , this code works in straight iPython:
# matplotlib with gt.graph_draw -- order important here import matplotlib as mpl mpl.use('cairo') # %matplotlib inline import matplotlib.pyplot as plt import graph_tool.all as gt # , graph_tool
x = [0,1] y = [0,1]
g = gt.Graph() pos = g.new_vertex_property('vector <float> ') v0 = g.add_vertex() v1 = g.add_vertex() e01 = g.add_edge(v0,v1) pos[v0] = [0,0] pos[v1] = [1,1]
plt.plot(x,y) ax = plt.gca() gt.graph_draw(g, pos=pos, mplfig=ax) plt.savefig('test.png')
But if I embed this code in a Jupyter notebook with the magic line "%matplotlib inline" uncommented, I do not get inline graphics, -- only a return object pointer. I'd greatly appreciate your thoughts if this Jupyter notebook capability would/should be possible. -- View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/... Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com.
On 01.01.2017 15:41, Steve wrote:
Thank you Tiago and feliz Ano Novo.
I hope I'm not getting greedy here, but I'd like to get this inline within a Jupyter Notebook.
I have graph_draw(mplfig=) working outside of a Jupyter notebook, and graph_draw itself works great inline within a Jupyter notebook.
It should be possible to get both together to produce nice annotations of graphs in a notebook.
Based on this Stackoverflow thread <http://stackoverflow.com/questions/34425955/make-coordinate-systems-agree-between-matplotlib-and-graph-tool> , this code works in straight iPython:
# matplotlib with gt.graph_draw -- order important here import matplotlib as mpl mpl.use('cairo') # %matplotlib inline import matplotlib.pyplot as plt import graph_tool.all as gt # , graph_tool
x = [0,1] y = [0,1]
g = gt.Graph() pos = g.new_vertex_property('vector <float> ') v0 = g.add_vertex() v1 = g.add_vertex() e01 = g.add_edge(v0,v1) pos[v0] = [0,0] pos[v1] = [1,1]
plt.plot(x,y) ax = plt.gca() gt.graph_draw(g, pos=pos, mplfig=ax) plt.savefig('test.png')
But if I embed this code in a Jupyter notebook with the magic line "%matplotlib inline" uncommented, I do not get inline graphics, -- only a return object pointer.
I'd greatly appreciate your thoughts if this Jupyter notebook capability would/should be possible.
Sorry for the late reply. Graph-tool uses cairo for drawing, and hence it only interplays with matplotlib when a cairo-compatible backend is being used. I believe that with Jupyter notebooks a HTML canvas backend is used, which is not cairo... It may be possible to force matplotlib to use a cairo-based image backend instead, but I'm not sure. Best, Tiago -- Tiago de Paula Peixoto <tiago@skewed.de>
participants (2)
-
Steve -
Tiago de Paula Peixoto