# How to simulate \`for\_each\_yaxis\` (from Python) in Julia?

**URL:** <https://discourse.julialang.org/t/how-to-simulate-for-each-yaxis-from-python-in-julia/75539>\
**Category:** Visualization\
**Tags:** plotlyjs\
**Created:** [January 31, 2022, 8:47pm UTC](https://discourse.julialang.org/t/how-to-simulate-for-each-yaxis-from-python-in-julia/75539 "2022-01-31T20:47:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mo-Gul](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mo-gul/32/33308_2.png) [@Mo-Gul](https://discourse.julialang.org/u/Mo-Gul)\
**Post date:** [January 31, 2022, 8:47pm UTC](https://discourse.julialang.org/t/how-to-simulate-for-each-yaxis-from-python-in-julia/75539/1 "2022-01-31T20:47:49Z")

</div>

The title says it all (again). Currently I state all the axes manually to change their styles like in

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

relayout!(
    p,
    xaxis=attr(showlines=true, mirror=true, linewidth=2),
    yaxis=attr(showlines=true, mirror=true, linewidth=2, linecolor="red"),
    yaxis2=attr(showlines=true, mirror=true, linewidth=2, linecolor="red"),
)

```

In Python you could do this for the y-axes with

```python
p.for_each_yaxis(
    lambda axis: axis.update(
        showline=True, mirror=True, linewidth=2, linecolor="red"
    )

```

Is there a way to so something similar in Julia?

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [June 20, 2022, 9:41am UTC](https://discourse.julialang.org/t/how-to-simulate-for-each-yaxis-from-python-in-julia/75539/2 "2022-06-20T09:41:53Z")

</div>

Here is one way:

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

```
