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?
Yes, just pass the axes or figure to the 'mplfig' parameter of graph_draw().
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
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
, this code works in straight iPython:
# matplotlib with gt.graph_draw -- order important here
import matplotlib as mpl
# %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
v0 = g.add_vertex()
v1 = g.add_vertex()
e01 = g.add_edge(v0,v1)
pos[v0] = [0,0]
pos[v1] = [1,1]
ax = plt.gca()
gt.graph_draw(g, pos=pos, mplfig=ax)
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.