xflr6 / graphviz

Simple Python interface for Graphviz
https://graphviz.readthedocs.io
MIT License
1.65k stars 213 forks source link

Plots cut off in Jupyter Notebook #224

Closed wjakob closed 2 months ago

wjakob commented 5 months ago

Hi,

I often run into issues where the Jupyter Lab visualization of a plot is cut off. An example:

Screenshot 2024-06-04 at 11 53 14

What could be the cause of this? I'm using the version 0.20.3 of this package and tried different GraphViz versions too. (It neither works with the distribution-provided Ubuntu GraphViz packages, nor with the latest deb packages from the GraphViz repo 2.43.0).

Other system parameters are: Ubuntu 22.04 / x86_64, Python 3.10.2.

Thanks, Wenzel

xflr6 commented 5 months ago

Hi, can you maybe provide the code for the example as a string for reproducability?

wjakob commented 5 months ago
import graphviz

graphviz.Source('''
digraph {
    rankdir=TB;
    graph [dpi=50 fontname=Consolas];
    node [shape=record fontname=Consolas];
    edge [fontname=Consolas];
    5 [label="{Evaluated |{Type: cuda f32|Size: 3}|{r5|Refs: 3}}}" fillcolor=lightblue2 style=filled];
    6 [label=" {mul|{Type: cuda f32|Size: 3}|{r6|Refs: 1}}}"];
    5 -> 6 [label=" 1"];
    5 -> 6 [label=" 2"];
    subgraph cluster_legend {
    label="Legend";
        l5 [style=filled fillcolor=yellow label="Placeholder"];
        l4 [style=filled fillcolor=yellowgreen label="Special"];
        l3 [style=filled fillcolor=salmon label="Dirty"];
        l2 [style=filled fillcolor=lightblue2 label="Evaluated"];
        l1 [stvle=filled fillcolor=wheat label="Labeled"];
        l0 [style=filled label="Constant"];
    }
}
''')

Further context that may be helpful: this issue does not appear when I run a Jupyter notebook locally on my laptop, which is a macOS 13.6.2 machine with Brew-installed Python 3.12.3, with Safari 17.1

It does appear when I SSH into a Linux box (running Ubuntu 22.04 / x86_64, Python 3.10.2, latest version of graphviz Python package and GraphViz itself) and access a Jupyter lab instance running there remotely through the browser on the Mac laptop. Perhaps it has something to do with the Linux box being a headless server, while the client has a high-DPI retina display.

xflr6 commented 5 months ago

Thanks. I agree with your suspicion that this might have something to do with the screen resolution settings in the specific environment where you see it. I cannot reproduce both with Jupyter Lab and Jupyter QtConsole. There is plenty of vertical space after the graph (rather too much than too lilttle):

Screenshot 2024-06-12 055620

Screenshot 2024-06-12 055539

I am fairly confident that the issue is not in this library (graphviz), maybe not even in upstream Graphviz. My best guess would be that it is in Jupyter. Maybe you could to try to reproduce the cut-off image more minimally somehow by using one of the https://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html#functions. Then you could report this over at https://github.com/jupyter/notebook/issues.