Discuss: Is It Time To Retire @pyplot Nodes?

17 views
Skip to first unread message

tbp1...@gmail.com

unread,
Nov 5, 2021, 10:45:42 AM11/5/21
to leo-editor
A node with a headline that starts with @pyplot can be displayed as a graph in the Viewrendered pane.  Viewrendered3 cannot do this currently, although I have working code that makes it work - and lets both VR and VR3 be open at the same time and either can render an @pyplot node to the rendering pane.

But @pyplot has some negatives.  I'd like to know what others think about them before I add the capability to VR3.

The way in which @pyplot works is simple but ingenious.  Matplotlib can render to a number of different "backends", including to a special Qt widget.  @pyplot creates a Qt widget embedded in the VR pane and draws the plot on that.  The code in VR also supplies numpy and matplotlib.pyplot as a convenience so they don't need to be imported.  Here are some issues I have found:

1. Writing and changing the pyplot code is painful, because at every few keystrokes, Matplotlib tries to execute the code but usually it isn't complete or valid while you are typing it.  VR3 can let you work around it by setting the Freeze state and reloading the node when you are done, but VR can't do this.

2. Once you have rendered an @pyplot node,  any other pyplot code you have in a non-pyplot node - which you might run with CTRL-B, for example - renders in the rendering pane instead of the usual Matplotlib rendering window.  This might be be all right in itself, but it means the behavior of the code changes depending on whether you have run an @pyplot node earlier - something you might not even remember having done.  This is not horrible but it can be jarring. 

3. Other plotting systems such as Holoviews that can use matplotlib for plotting are not likely to work as is.  I have some experimental changes that let Holoviews work, and plotnine works as is (IIRC), but it's awkward to have to remember what works and what doesn't.

4. It's not clear (to me, at least) what the intended use case is.  The code you need for an @pyplot node is the same as for a non-pyplot one that does the same thing, except for a few imports.  You do get rendering in the rendering pane, but that is usually smallish in size.  With VR3, it is simple to save the plot as an image file and show that image in the rendering pane, so not much has been gained.  If you want to include a plot in a longer document (in notebook style, like Jupyter), you can do that easily with VR3 but an @pyplot node can't accomplish it.

5. @pyplot nodes are not especially good for a quick look at some data, because you have to write the code to plot it.  And if the data come from a file, you have to read and parse that.  The new Plot 2D function in VR3 lets you show at least the most common type of plot with no coding at all.  So @pyplot nodes have been superseded if what you want are quick and easy X-Y graphs.
Reply all
Reply to author
Forward
0 new messages