Basic Dot Plot Error

Hello Watchers:

Executing commands in Pluto 0.18.*
I am using StatsPlots and PlotlyJS (with plotlyjs()
activated as a back-end) in Julia 1.8.*

When executing the following instructions:

Lab_Entity = ["Lab1", "Lab2", "Lab3", "Lab4", "Lab5"]

trace1 = stp.scatter(
    x=[0.959311, 0.562546, 0.781273, 1.0, 0.176317, 0.176317],
    y=Lab_Entity,
    marker=attr(color="crimson", size=12),
    mode="markers",
    name="CoH",
)
trace2 = stp.scatter(
    x=[0.214919, 0.188576, 0.17397, 0.18988, 0.13302, 0.13302],
    y=Lab_Entity,
    marker=attr(color="gold", size=12),
    mode="markers",
    name="D2C"
)
trace3 = stp.scatter(
    x=[0.0102765, 0.0102765, 0.0104851, 0.0105634, 0.0106416, 0.0106416],
    y=Lab_Entity,
    marker=attr(color="blue", size=12),
    mode="markers",
    name="CR"
)
layout = Layout(title="Compare Plot",
                  xaxis_title="Measurement",
                  yaxis_title="Lab Entity")

stp.plot([trace1,trace2,trace3], layout)

This returns the following error:

MethodError: no method matching getindex(::Nothing, ::Int64)

I believe this has something to do with attempting
to plot a Float64? eltype. Might anyone have a
work around?

You are mixing PlotlyJS syntax with StatsPlots functions, that is not going to work.
You’d have to use the Plots.jl syntax when using StatsPlots. E.g.

trace2 = stp.scatter([0.214919, ..., 0.13302], Lab_Entity, marker = (:gold, 12), label = "D2C")

etc.

2 Likes

@BeastyBlacksmith – thank you for your reply.

I have rewritten the blocks above as:

using StatsPlots
   const stp = StatsPlots

Lab_Entity = ["Lab1", "Lab2", "Lab3", "Lab4", "Lab5", "Lab6"]
CH = [0.959311, 0.562546, 0.781273, 1.0, 0.176317, 0.176317]
D2C = [0.214919, 0.188576, 0.17397, 0.18988, 0.13302, 0.13302]
CrR = [0.0102765, 0.0102765, 0.0104851, 0.0105634, 0.0106416, 0.0106416]

trace1 = stp.scatter(
    CH,
    Lab_Entity,
    marker = (:crimson, 12),
    label="CoH",
)
trace2 = stp.scatter(
    D2C,
    Lab_Entity,
    marker = (:gold, 12),
    label="D2C"
)
trace3 = stp.scatter(
    CrR,
    Lab_Entity,
    marker = (:blue, 12),
    label="CR"
)
l = @layout([title="Entity Compare";
            ylab="Measurement";
            xlab="Lab Entity"])

stp.plot([trace1,trace2,trace3], l)

Which is returning the error:

no method matching getindex(::Nothing, ::Int64)

I am not iterating over a dictionary, using StatLint
or JuMP. Could you point out what I am missing?

Have you considered my advice from the previous discussion here:

?

Again your piece of code isn’t an MWE that reproduces your problem. In this case it’s possible to fix it (by adding import StatsPlots as stp at the top, and fixing the second scatter call by adding a comma after (:gold, 12)), but again this is just unnecessary overhead for people trying to help you.

The answer to your question is that this

l = @layout([title="Entity Compare";
            ylab="Measurement";
            xlab="Lab Entity"])

still isn’t Plots/StatsPlots syntax, here’s the documentation for layouts:

https://docs.juliaplots.org/stable/layouts/#Advanced-Layouts

@nilshg

I thought it would be obvious to an
expert that I was using StatsPlots especially
since I indicated as much in the opening
statement of the post. In my case, I provided
the following instructions:

using StatsPlots
const stp = StatsPlots

I referenced Plots link before you mentioned it
which is what motivated:

l = @layout([title="Entity Compare";
            ylab="Measurement";
            xlab="Lab Entity"])

I did not mention I was using Pluto
not the REPL. Which might require
subtle adjustments to commands in
some cases. I have updated it.

Lastly, folks default to saying provide a
MWE, but I have noticed it is not always
necessary to uncover issues – in this
case it may be more syntax (spelling),
logic (command order), rather than some
more advanced run-time(system-level)
issue. A professional dev or programmer
could identify this without having to
reproduce the code block + problem.