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

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

# 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:

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

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

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.

1 Like

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.

1 Like

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

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

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 " " "

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.

There appears to be a way: Type backquote on iPad

1 Like

Thanks, this is really helpful

Here’s the correctly formatted code

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.