# Warnings on assigning marker size in Plots.jl to a variable

**URL:** <https://discourse.julialang.org/t/warnings-on-assigning-marker-size-in-plots-jl-to-a-variable/93067>\
**Category:** New to Julia\
**Tags:** plots\
**Created:** [January 17, 2023, 5:17am UTC](https://discourse.julialang.org/t/warnings-on-assigning-marker-size-in-plots-jl-to-a-variable/93067 "2023-01-17T05:17:28Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![arinbasu1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arinbasu1/32/45571_2.png) [@arinbasu1](https://discourse.julialang.org/u/arinbasu1)\
**Post date:** [January 17, 2023, 5:17am UTC](https://discourse.julialang.org/t/warnings-on-assigning-marker-size-in-plots-jl-to-a-variable/93067/1 "2023-01-17T05:17:28Z")

</div>

Hi All,  
I was trying to create a forestplot using the following code:

```julia
# plot author on y axis
# tE on x axis,
# add whiskers
function forestplot(df, author, tE, seTE, wt)
    wt = df.wt
plot(df.tE, df.author,
    seriestype = :scatter,
    markershape = :rect,
    markersize = wt,
    xerr = df.seTE,
legend = false)
end

forestplot(df, :author, :tE, :seTE, :wt)

```

the associated data here:

```julia
author = ["a", "b", "c", "d", "e"]
tE = [1.23, 1.34, 1.45, 1.56, 1.67]
seTE = [0.23, 0.24, 0.34, 0.56, 0.67]
df = DataFrame(Dict(
        "author" => author,
        "tE" => tE,
        "seTE" => seTE))
df.wt = 1 ./ df.seTE .^2

```

The plot renders but issues the following warning

```julia
Warning: Indices Base.OneTo(5) of attribute `markersize` does not match data indices 2:15.
└ @ Plots ~/mambaforge/share/julia/packages/Plots/nqFaB/src/utils.jl:141
┌ Info: Data contains NaNs or missing values, and indices of `markersize` vector do not match data indices.
│ If you intend elements of `markersize` to apply to individual NaN-separated segments in the data,
│ pass each segment in a separate vector instead, and use a row vector for `markersize`. Legend entries
│ may be suppressed by passing an empty label.

```

The data does not contain NaN, so I am not sure how to interpret this warning.  
I’d greatly appreciate any insights and helpful pointers.  
Kind Regards,  
Arindam Basu

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [January 17, 2023, 6:58am UTC](https://discourse.julialang.org/t/warnings-on-assigning-marker-size-in-plots-jl-to-a-variable/93067/2 "2023-01-17T06:58:37Z")

</div>

If you look closely you’ll see that it’s reshaping the “markers” at the ends of the error bars as well - this is why it thinks there should be `3 * 5 = 15` sizes (not sure where the `2:15` comes from). I would consider reporting this on the `Plots` Github page.

---

<div class="post-metadata">

**Author:** ![arinbasu1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arinbasu1/32/45571_2.png) [@arinbasu1](https://discourse.julialang.org/u/arinbasu1)\
**Post date:** [January 17, 2023, 8:56am UTC](https://discourse.julialang.org/t/warnings-on-assigning-marker-size-in-plots-jl-to-a-variable/93067/3 "2023-01-17T08:56:31Z")

</div>

Thanks @gustaphe  
Seems I have to do something like

‘’’  
x = [[t] for t in df.tE]  
y = [[ a] for a in df.author ]  
w = reshape(df.wt, 1, nrow(df) )

Then the plot with something like  
plot(  
x, y, seriestype = :scatter,  
markershape = :rect,  
markersize = w  
)

‘’’  
To make it work without warning.  
So [t] and [a] form the pair to define the individual points to which the size applies drawn from the matrix w for each element mapped to the a ,t pair.

---

<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 17, 2023, 11:05am UTC](https://discourse.julialang.org/t/warnings-on-assigning-marker-size-in-plots-jl-to-a-variable/93067/4 "2023-01-17T11:05:24Z")

</div>

Note that instead of vectors of singleton vectors, we could provide row vectors to plot:

```julia
plot(df.tE', permutedims(df.author),
    st=:scatter, markershape=:rect, ms=df.wt',
    xerr=df.seTE, legend=false
)

```

---

<div class="post-metadata">

**Author:** ![devel-chm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/devel-chm/32/3572_2.png) [@devel-chm](https://discourse.julialang.org/u/devel-chm)\
**Post date:** [January 18, 2023, 7:09pm UTC](https://discourse.julialang.org/t/warnings-on-assigning-marker-size-in-plots-jl-to-a-variable/93067/5 "2023-01-18T19:09:01Z")

</div>

> [@arinbasu1](#):
>
> ‘’’

You need to use backquotes to get the syntax formatting  
for julia code. If you are using the discourse forum editor  
you can click on the “\</\>” button to get the appropriate  
characters, " ` " and not " ’ " or " " "

---

<div class="post-metadata">

**Author:** ![arinbasu1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arinbasu1/32/45571_2.png) [@arinbasu1](https://discourse.julialang.org/u/arinbasu1)\
**Post date:** [January 18, 2023, 7:23pm UTC](https://discourse.julialang.org/t/warnings-on-assigning-marker-size-in-plots-jl-to-a-variable/93067/6 "2023-01-18T19:23:31Z")

</div>

That was because I wrote these `codes` using an iPad where I did not have the backticks on the keyboard. Had I used a notebook/desktop I’d have correctly written the codes. I will edit it and thanks for understanding.

---

<div class="post-metadata">

**Author:** ![devel-chm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/devel-chm/32/3572_2.png) [@devel-chm](https://discourse.julialang.org/u/devel-chm)\
**Post date:** [January 18, 2023, 11:47pm UTC](https://discourse.julialang.org/t/warnings-on-assigning-marker-size-in-plots-jl-to-a-variable/93067/7 "2023-01-18T23:47:01Z")

</div>

There appears to be a way: [Type backquote on iPad](https://meta.stackexchange.com/questions/133673/is-there-a-way-to-enter-back-tick-backtick-on-so-when-using-ipad-or-iphone)

---

<div class="post-metadata">

**Author:** ![arinbasu1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arinbasu1/32/45571_2.png) [@arinbasu1](https://discourse.julialang.org/u/arinbasu1)\
**Post date:** [January 19, 2023, 8:36am UTC](https://discourse.julialang.org/t/warnings-on-assigning-marker-size-in-plots-jl-to-a-variable/93067/8 "2023-01-19T08:36:06Z")

</div>

Thanks, this is really helpful

Here’s the correctly formatted code

```julia
x = [[t] for t in df.tE]
y = [[ a] for a in df.author ]
w = reshape(df.wt, 1, nrow(df) )

Then the plot with something like
plot(
x, y, seriestype = :scatter,
markershape = :rect,
markersize = w
)

```

Note this not the best solution of course, the better solution is provided above by Rafael Guerra.
