Y position is misaligned when rendering with matplotlib
When rendering to a matplotlib figure, the graph-tool plot is slightly misaligned on the y-axis. This can be observed by altering the y limit in matplotlib.
import matplotlib.pyplot as plt import graph_tool.all as gt g = gt.price_network(500) pos = gt.sfdp_layout(g) plt.switch_backend('cairo') fig, ax = plt.subplots() ax.set_aspect(1) res = gt.graph_draw(g, pos=pos, mplfig=ax) ylim = ax.get_ylim() xlim = ax.get_ylim() ax.set_ylim(ylim/2, ylim/2) ax.set_xlim(xlim/2, ylim/2) plt.savefig('gt_test.pdf')
These warnings are produced:
/usr/lib/python3.8/site-packages/graph_tool/draw/cairo_draw.py:637: UserWarning: Unknown parameter: layout_K warnings.warn("Unknown parameter: " + k, UserWarning) /usr/lib/python3.8/site-packages/graph_tool/draw/cairo_draw.py:637: UserWarning: Unknown parameter: update_layout warnings.warn("Unknown parameter: " + k, UserWarning)
You will notice that the nodes and edges are visible slightly above the top, and are clipped too soon on the bottom. Despite modifying x limits in the same way the clipping works correctly there. I've tried plotting other things with
ax.scatter() and those things will be clipped correctly, so this seems graph-tool specific.
I also noticed making this demo that the arrow heads are not hidden outside the matplotlib axes, but I guess that's probably a separate issue.
Are you running the latest
Do you observe the problem with the current git version?
Did you compile
(Compiled using the PKGBUILDs available on the Arch User Repository. I should note also that I had to use this patch to fix the boost coroutine header included with Arch before it would compile.)
- OS: Arch Linux
- Python: 3.8 (installed from arch repos)
- Matplotlib: 3.1.3 (installed from arch repos)
- Boost libs: 1.72 (installed from arch repos)
- Compiler: GCC 9.2.0
Behaviour seems identical between latest release and git version.