Search code examples
dataframeplotlyjulia

Scatter plot of two rows of a DataFrame in Julia using Plotly


I have a dataframe and I want to create a scatter plot of columns 2:10 of the first and third rows of the data using Plotly, and also have the column names in the legend (each column in a different color).

I'm trying to do the following as a start:

scat = scatter(; x=Array(df[3,2:end]),
                y=Array(df[1,2:end]),
                name=names(df[3,2:end]),
                mode="markers")
plot(scat, Layout(title="Metrics", showlegend=true))

But I'm only getting the same color for each column in the scatter plot, and only one item in the legend called trace 0. How can I color each point in a different color and have it as an item in the legend named with the column name?

Thank you!


Solution

  • I solved it using Plotly in the following way in case someone is interested:

    sc = GenericTrace[]
    
        for i in 2:ncol(df)
            push!(sc, scatter(x=[df[3, i]], y=[df[1, i]], mode="markers", name=names(df)[i]))
        end
    plot(sc, Layout(title="Title", 
                    showlegend=true))