# Change each trace meeting condition in PlotyJS plot

**URL:** <https://discourse.julialang.org/t/change-each-trace-meeting-condition-in-plotyjs-plot/75474>\
**Category:** Visualization\
**Tags:** plotlyjs\
**Created:** [January 30, 2022, 7:38pm UTC](https://discourse.julialang.org/t/change-each-trace-meeting-condition-in-plotyjs-plot/75474 "2022-01-30T19:38:58Z")\
**Posts on this page:** 6\
**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 30, 2022, 7:38pm UTC](https://discourse.julialang.org/t/change-each-trace-meeting-condition-in-plotyjs-plot/75474/1 "2022-01-30T19:38:58Z")

</div>

The title states it all. Here an example with the Julia code without the requested part.

```nohighlight
using DataFrames
using PlotlyJS

df = DataFrame(
    x = 1:5,
    a = rand(5),
    b_calc = rand(5),
    c = rand(5),
    d_calc = rand(5)
)

fig = plot()
for tag in [:a, :b_calc, :c, :d_calc]
    add_trace!(fig, scatter(x=df.x, y=df[!, tag], name=tag))
end

```

In Python a possible example of the requested part would be

```python
# corresponding Python code of what I want to achieve in Julia
# adapt line style when the trace name ends with "_calc"
fig.for_each_trace(
    lambda trace:
        trace.update(
            line_dash="dash",
        ) if trace.name.endswith("_calc") else (),
)

```

Unfortunately I couldn’t find an equivalent of `for_each_trace` in the corresponding Julia documentation parts. I had a look at

- [https://github.com/JuliaPlots/PlotlyJS.jl/blob/master/docs/src/manipulating\_plots.md](https://github.com/JuliaPlots/PlotlyJS.jl/blob/master/docs/src/manipulating_plots.md) and
- [Fundamentals in Julia](https://plotly.com/julia/plotly-fundamentals/)

Can this be achieved without such an equivalent command which is the reason it doesn’t exist?

---

<div class="post-metadata">

**Author:** ![stephancb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stephancb/32/14243_2.png) [@stephancb](https://discourse.julialang.org/u/stephancb)\
**Post date:** [January 30, 2022, 8:48pm UTC](https://discourse.julialang.org/t/change-each-trace-meeting-condition-in-plotyjs-plot/75474/2 "2022-01-30T20:48:35Z")

</div>

```julia
for (k,it) in enumerate(fig.plot.data)
    if endswith(String(it[:name]), "_calc")
        restyle!(fig, k, line_dash="dash")
    end
end

```

---

<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 30, 2022, 9:02pm UTC](https://discourse.julialang.org/t/change-each-trace-meeting-condition-in-plotyjs-plot/75474/3 "2022-01-30T21:02:48Z")

</div>

@stephancb, awesome. I would have never come to `fig.plot.data`. Even can’t remember to have seen this anywhere. Many thanks !!

---

<div class="post-metadata">

**Author:** ![stephancb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stephancb/32/14243_2.png) [@stephancb](https://discourse.julialang.org/u/stephancb)\
**Post date:** [January 30, 2022, 9:13pm UTC](https://discourse.julialang.org/t/change-each-trace-meeting-condition-in-plotyjs-plot/75474/4 "2022-01-30T21:13:16Z")

</div>

I had figured it out with

```julia
julia> fieldnames(typeof(fig))
(:plot, :scope, :window)

julia> fieldnames(typeof(fig.plot))
(:data, :layout, :frames, :divid, :config)

```

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 30, 2022, 9:26pm UTC](https://discourse.julialang.org/t/change-each-trace-meeting-condition-in-plotyjs-plot/75474/5 "2022-01-30T21:26:51Z")

</div>

Just in case, we can also drill down by typing in the REPL: `fig.` followed by `<TAB> <TAB>`, and so on.

Or even better, use the new `Eyeball` package with the command: `eye(fig)`

---

<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, 7:05pm UTC](https://discourse.julialang.org/t/change-each-trace-meeting-condition-in-plotyjs-plot/75474/6 "2022-01-31T19:05:21Z")

</div>

I am new to Julia so I am very thankful for your hints, guys 👍
