Modify PlotlyJS-Templates

In the current documentation for PlotlyJS the description how to modify available Styles/Templates is outdated :frowning:
This is a known issue: Style() not defined
Based on the information in this thread I experimented a bit with the function PlotlyJS.Template(). Below my example.
Here is my question regarding the topic of equal style of axes, is it possible to
specify via a Template to format each axis in the same color and thickness?
The predefined PlotlyJS-Template simple_white is already close to what I would
like to achieve, but I would like to specify e.g. the axis line-thickness as well.
Are there any ideas?

using PlotlyJS
# --------------------------------------------------------------------------------------------------------------------------
# --- Info about Template():    https://github.com/JuliaPlots/PlotlyJS.jl/issues/408
# --- available templates:      PlotlyJS.templates
# for (key_, value_) in PlotlyJS.templates.templates
#     println(key_)
# end
# --------------------------------------------------------------------------------------------------------------------------
# --- modify existing template:
plt_layout = PlotlyJS.Layout(;
    template         = PlotlyJS.templates.simple_white,
    title_font_size  = 28,
    font_size        = 20, 
    legend_font_size = 20,
    xaxis_linewidth  = 2.0,     # it does not work :-(
    yaxis_linewidth  = 2.0,     # it does not work :-(
    yaxis2_linewidth = 2.0,     # it does not work :-(
    yaxis2_linecolor = "black", # it does not work :-(
    linewidth        = 2.0,     # it does not work :-(
    linecolor        = "black", # it does not work :-(
)
MyTemplate          = PlotlyJS.Template(layout = plt_layout)
# --- plot function:
function plot_with_template(_template::PlotlyJS.Template=PlotlyJS.templates.plotly)
    plt_trace_1 = PlotlyJS.scatter(; x = [0, 1], y = [0, 1], name = "trace1", mode = "lines+markers", legendrank = 1, line_dash = "dash", marker_symbol = "diamond", marker_size = 15)
    plt_trace_2 = PlotlyJS.scatter(; x = [0, 1], y = [1, 0], name = "trace2", mode = "lines+markers", legendrank = 2, line_dash = "dashdot", yaxis= "y2")
    plt_data = [plt_trace_2, plt_trace_1]
    hdl_layout = PlotlyJS.Layout(;
        template        = _template,
        title_text      = "Title_Text2",
        xaxis_title     = "x-axis",
        yaxis_title     = "1st y-axis",
        yaxis_constrain = "domain",
        yaxis_range     = [0, 1],
        yaxis2 = PlotlyJS.attr(;
            title       = "2nd y-axis",
            overlaying  = "y",
            side        = "right",
            constrain   = "domain",
            range       = [0, 1],
            # linecolor   = "black", # this works only for one axis
            # linewidth   = 2.0,     # this works only for one axis
        ),
    )
    # ---
    return PlotlyJS.Plot(plt_data, hdl_layout)
end

# --- some plot examples:
hdl_plt = plot_with_template(MyTemplate)

plot_with_template() # plot with default template "plotly"
plot_with_template(PlotlyJS.templates.simple_white)

You can set axis thickness in your template, as linewidth, in pixels, and color as linecolor.

1 Like

Thanks! That works :slight_smile:

plt_layout = PlotlyJS.Layout(;
    template            = PlotlyJS.templates.simple_white,
    height              = 400,
    width               = trunc(Int, sqrt(2) * 400),
    title_font_size     = 28,
    font_size           = 20, 
    legend_font_size    = 20,
    xaxis               = PlotlyJS.attr(; 
        linewidth = 2.0,
        linecolor = "rgb(36,36,36)",
        zeroline  = false,
        showline  = true,
        ),
    yaxis               = PlotlyJS.attr(; 
        linewidth = 2.0,
        linecolor = "rgb(36,36,36)",
        zeroline  = false,
        showline  = true,
        ),
)
MyTemplateHalfTextWidth  = PlotlyJS.Template(layout = plt_layout)