Today it gave me a headache to understand how to plot two subplots, one with a single y-axis and another with two y-axis with specific axis titles. The logic seems to be, each subplot with one y-axis adds 1 y-axis and each subplot with two y-axis adds 2 y-axis
to the overall count of y-axis.
Below my example, I hope this helps others to understand the logic.
I do not know, if this is the recommended way to do the job in PlotlyJS
, but it works for me (which is fine ).
using PlotlyJS
# -------------------------------------------------------------------------------------------------
# Example to configure the title of a specific axis in a specific subplot:
# -------------------------------------------------------------------------------------------------
hdl_trace1 = PlotlyJS.scatter(x=[0, 1], y=[1, 2], name="(r1, c1)")
hdl_trace2 = PlotlyJS.scatter(x=[1, 3], y=[2, 3], name="1st(r2, c1)")
hdl_trace3 = PlotlyJS.scatter(x=[1, 3], y=[2, 1], name="2nd(r2, c1)")
# --- layout of plot with subplots: Column1
hdl_plt = PlotlyJS.make_subplots(rows=2, cols=1, specs = [ Spec(kind="xy", secondary_y = false) missing; # row 1
Spec(kind="xy", secondary_y = true) missing]) # row 2
# --- define traces:
PlotlyJS.add_trace!(hdl_plt, hdl_trace1, row = 1, col = 1)
PlotlyJS.add_trace!(hdl_plt, hdl_trace2, row = 2, col = 1)
PlotlyJS.add_trace!(hdl_plt, hdl_trace3, row = 2, col = 1, secondary_y = true)
# --- comon title and size:
PlotlyJS.relayout!(hdl_plt, height=500, width=450, title_text = "Example subplots: two row by one colum plot")
# --- count number of yaxis, two subplots: a) one yaxis, b) two yaxis => 3 yaxis, yaxis3 needs to be formated
PlotlyJS.relayout!(hdl_plt,
yaxis = PlotlyJS.attr(; title = "y-axis <b>1</b>", ),
yaxis2 = PlotlyJS.attr(; title = "y-axis <b>2</b>", ),
yaxis3 = PlotlyJS.attr(; title = "y-axis <b>3</b>", ))
# --- show plot and safe plot as json:
PlotlyJS.display(hdl_plt)
PlotlyJS.savefig(hdl_plt, raw"c:\tmp\plt\two_plts.json")