# Modify PlotlyJS-Templates

**URL:** <https://discourse.julialang.org/t/modify-plotlyjs-templates/89251>\
**Category:** General Usage\
**Tags:** plotlyjs\
**Created:** [October 25, 2022, 2:58pm UTC](https://discourse.julialang.org/t/modify-plotlyjs-templates/89251 "2022-10-25T14:58:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [October 25, 2022, 2:58pm UTC](https://discourse.julialang.org/t/modify-plotlyjs-templates/89251/1 "2022-10-25T14:58:19Z")

</div>

In the current documentation for `PlotlyJS` the description how to modify available Styles/Templates is outdated ☹  
This is a known issue: [Style() not defined](https://github.com/JuliaPlots/PlotlyJS.jl/issues/408)  
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?

```julia
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)

```

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [October 25, 2022, 3:21pm UTC](https://discourse.julialang.org/t/modify-plotlyjs-templates/89251/2 "2022-10-25T15:21:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [October 25, 2022, 3:36pm UTC](https://discourse.julialang.org/t/modify-plotlyjs-templates/89251/3 "2022-10-25T15:36:10Z")

</div>

Thanks! That works 🙂

```julia
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)

```
