How do you draw (x, y) scatter plots according to the values ​​in z using Plots.jl?

Using the Julia Plots.jl package, I can use various servers to create a scatter plot based on two vectors xandy

k = 100
x = rand(k)
y = rand(k)
scatter(x, y)

I cannot find information on how to color them according to the length of the kvector z. How do you do this?

+4
source share
2 answers

, jverzani ( ). , , .

using Plots
pyplot(size=(400,200), legend=false)  # set backend and set some session defaults

scatter(rand(30),
        m = ColorGradient([:red, :green, :blue]),  # colors are defined by a gradient
        zcolor = repeat( [0,0.5,1], 10) # sample from the gradient, cycling through: 0, 0.5, 1
       )

enter image description here

+3

, k , : scatter(x, y, markercolors=k), . , , :

using Plots

xs = rand(10)
ys = rand(10)
ks = randbool(10) + 1 # 1 or 2
mcols = [:red, :blue]  # together, mcols[ks] is the `k` in the question

p = scatter(xs[ks .== 1], ys[ks .== 1], markercolor=mcols[1])
for k = 2:length(mcols)
    scatter!(xs[ks .== k], ys[ks .== k], markercolor=mcols[k])
end
p
+2

Source: https://habr.com/ru/post/1626849/


All Articles