jupyter-xeus / xeus-octave

Jupyter kernel for GNU Octave
https://xeus-octave.readthedocs.io/
GNU General Public License v3.0
57 stars 10 forks source link

Title of a plot does not show when using graphics_toolkit("plotly") #113

Closed cjwomack closed 7 months ago

cjwomack commented 7 months ago

Description

I was attempting to add a title eg [ title("Intensity of a doughnut-shaped laser beam")] to a plot using graphics_toolkit("plotly") . This doesn't work unless you use the notebook mode for graphics_toolkit.

What I Did

I was attempting to add a title to a plot using graphics_toolkit("plotly") . This doesn't work unless you use the notebook mode for graphics_toolkit.

Doesn't look like this is currently implemented when looking at https://github.com/jupyter-xeus/xeus-octave/blob/main/src/tk_plotly.cpp

Also looked at trying to use the text() function but didn't work in conjunction with plot. A rough solution is to use disp() with \n for a new line and spaces to roughly center it.

Anyway, it does say experimental re plotly in your binder book so no great issue.

cjwomack commented 7 months ago

Mentioned status in https://github.com/jupyter-xeus/xeus-octave/issues/13

Sorry.

cjwomack commented 7 months ago

Looks like it is easy to add a title using Plotly JSON, but hard to grab title of a plot from Octave - most likely iterating over children of graphics-object ... You can easily add the figure text as a title but not useful eg Figure 1 https://github.com/jupyter-xeus/xeus-octave/blob/main/src/tk_plotly.cpp to be placed after line 73 re useless figure title code...

std::string figureTitle = figureProperties.get_title(); // gives useless Figure X
plot["layout"]["title"]["text"] = "<b>" + figureTitle + "</b>"; // html for bold
plot["layout"]["title"]["x"] = 0.5; // Center the text horizontally
plot["layout"]["title"]["y"] = 0.875; // 1 is top of graph, 0 is bottom of graph
plot["layout"]["title"]["font"]["size"] = 18; //font size
cjwomack commented 7 months ago

https://github.com/gnu-octave/octave/blob/10e87950b9ec28afe71fa1acda1d435d4f3c1297/scripts/plot/util/private/gnuplot_draw_axes.m#L1214

You can get the title from the axis object.

However, it gets tricky when there are subplots in a figure these titles get mapped to annotations