python-igraph icon indicating copy to clipboard operation
python-igraph copied to clipboard

The default plot size is too large for use in notebooks

Open szhorvat opened this issue 4 years ago • 6 comments

Describe the bug The default plot size is too large to be usable in notebooks. This is a serious usability issue. Ideally, newcomers should be able to visualize graphs immediately and conveniently when working in notebooks, thus the plot size should be reasonable out-of-the box. At the very least, there should be an easy way to set up a convenient default plot size, without significant ipython/python/jupyter knowledge. This way should be mention in the introductory tutorials.

This is in the spirit of making igraph accessible to everyone, a major point in our recent proposal.

To reproduce

Example from a reasoanably-size VSCode window (it's the same in any browser).

image

Version information 0.9.1

szhorvat avatar May 20 '21 16:05 szhorvat

This is the point where we need to decide whether python-igraph should be able to detect whether it's running inside a notebook environment, and act accordingly if it does. The default plot size was set up under the assumption that the plot will be shown in a separate window and will be closed once the user is done with it (or saved for posterity if the plot is meant for a publication). Clearly this is not suitable for notebooks, but a smaller default plot size would not be useful for the former use-case.

However, it may be the case that plotting graphs in separate windows is sooooo 20th century now that we should not need to optimize for that use-case so we can set up the default plot size for notebooks and ask the user to override it for publications (which is probably the less frequent use-case).

Any opinions?

ntamas avatar May 20 '21 19:05 ntamas

However, it may be the case that plotting graphs in separate windows is sooooo 20th century now that we should not need to optimize for that use-case

It would be good to get an idea of how most people use igraph.

I think many people like to use a MATLAB-inspired IDE like Spyder. That's another thing to consider.

This is the point where we need to decide whether python-igraph should be able to detect whether it's running inside a notebook environment

That might be useful, as several features make sense in notebooks. Or there could be a manual switch that enables "notebook mode". I don't know how other Python packages handle this. networkx figures are more reasonably sized in notebooks.

szhorvat avatar May 20 '21 20:05 szhorvat

I use Python+vim which is (early) 20th century but efficient: open a matplotlib window (Qt5), zoom in the plot if you want to, save it to file at the desired dpi or in a vector format, done.

Most young folks despite this traditional art though, and instead make a png that embeds in the notebook.

As far as mpl is concerned, I agree with Szabolcs, a smaller embedded png is the current fashion and we should follow. You can still save at whatever dpi you like for publication.

I'm unsure if the same dpi upscaling can be achieved in Cairo directly. Clearly, in mpl it works because they have an internal vector representation of the plot (fig = plt.gcf(), for many notebook cases) that persists beyond and independently of the embedded png

iosonofabio avatar May 20 '21 21:05 iosonofabio

I'm unsure if the same dpi upscaling can be achieved in Cairo directly

I'm pretty sure it's not unless you jump through extra hoops to store the internal representation. Cairo is "just" a vector drawing tool that takes a surface (screen, image buffer, PDF file, OpenGL context etc), draws some stuff on it, saves it and then forgets about it. It is probably comparable to the Matplotlib drawing backends (e.g., the Agg backend), and is at roughly the same abstraction level. Matplotlib has built up an entire machinery on top of it that stores a representation of the plot at the point where it is not sent to the backend yet.

ntamas avatar May 21 '21 09:05 ntamas

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 20 '21 09:07 stale[bot]

matplotlib is reasonably notebook-friendly, while plotly is "web first" and has several renderers dedicated to notebooks, jupyterlab, embedded html, etc. I feel like trying to embed a Cairo-made PNG into notebooks is destined to fall out of favour as time passes, and we could instead recommend people to switch to another backend through a config value in the near future.

iosonofabio avatar Aug 20 '21 05:08 iosonofabio