Using group in scatter plots correctly?

Hello!

I am trying to make a scatterplot where there exist two groups, one called “0” and one called “1”. The group values is stored in a vector “z”. Over time the points in group “0”, come to group “1”, something like this:

image

image

But in the final time step, when all have come to group “1”, the color just becomes “blue” - I want it to stay orange or some other color I set:

image

How do I achieve this, using Plots? My current command is:

p = scatter((data[1,:],data[2,:]),
            group = z,
            markersize = 3.5,
            markerstrokestyle = :dot,
            aspect_ratio=:equal
            );

Kind regards

The easiest solution here is to pull a slight of hand and make the orange group 0 and the blue group 1, then use the labels option to change your legend and the colors option to change the colors.

Hi!

To do this I would need to split my data some way, and I am not sure how to do it correctly in Julia. In Matlab I would use “~” to get reverse indices, i.e. if I have a vector of 0 and 1, then using “~”, I could switch it to 1 and 0 - hope it makes sense.

How would I do that in Julia?

Kind regards

I managed to get it to work now using “findall”. Now I wonder how can I remove a legend entry (a label), when no more exist?

Kind regards

I think you are looking for:

p = scatter((data[1,:],data[2,:]),
                   group = z,
                   color_palette=[:orange,:black],
                   markercolor=:match,
                   markersize = 3.5,
                   markerstrokestyle = :dot,
                   aspect_ratio=:equal
                   )

Thanks for your suggestion, but unfortunately, it did not work as expected.

I switched to PGFPlotsX backend, now it works as I want:

image

Kind regards, and thanks for the help everybody