How to simulate `for_each_yaxis` (from Python) in Julia?

Here is one way:

using PlotlyJS

p = make_subplots(
    rows=2,
    cols=1,
    shared_xaxes=true,
    
);

add_trace!(p, scatter(y=1:2), row=1, col=1)
add_trace!(p, scatter(y=1:2), row=2, col=1)

## Gets y axes as fall back, or use "x" etc. in second argument to get other ones:
get_axes(q::PlotlyJS.SyncPlot, dm::String="y") = filter(z -> occursin(dm*"axis",string(z)), keys(q.plot.layout))

# Define your updates to axis properties here:
update_dict = Dict(:showlines => true, :mirror => true, :linewidth => 2, :linecolor => "red")

for ax in get_axes(p,"y")
    merge!(p.plot.layout[ax], update_dict)
end

relayout!(
    p,
    xaxis=attr(showlines=true, mirror=true, linewidth=2)
)
display(p)
1 Like