Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colouring indivdual scatter points #55

Open
GrimmSnark opened this issue Jul 28, 2022 · 5 comments
Open

Colouring indivdual scatter points #55

GrimmSnark opened this issue Jul 28, 2022 · 5 comments

Comments

@GrimmSnark
Copy link

Hello,

First of all this is a beautiful function and the plots look gorgeous.

So I am plotting three violin plots on the same axis. However, I would like to specify the individual colours of some of the scatter points.

With scatter you can specify an m x 3 rgb array for each point. Is there any way to do this function?

Best,

Michael

@bastibe
Copy link
Owner

bastibe commented Jul 28, 2022

You can access the scatter plots directly as Violin.ScatterPlot and Violin.ScatterPlot2. Feel free to modify them in any way you like!

@GrimmSnark
Copy link
Author

GrimmSnark commented Jul 29, 2022

Hello,

Yes I can do that if I want to change all the scatter point colours to an other colour completely using:

violinHandle(1).ScatterPlot.MarkerFaceColor = [0 0 0];

However, if I want to make each scatter point a different colour like you can with the normal scatter plot function by calling:

violinHandle(1).ScatterPlot.CData = [m X RGB];

I get no change in colour. Any help would be greatly appreciated!

Michael

@bastibe
Copy link
Owner

bastibe commented Aug 2, 2022

No idea, sorry. At this point you're dealing with a plain-old Matlab scatter plot. If changing CData doesn't work, perhaps open a support ticket at Mathworks (I'm not kidding, they are very helpful there). Violinplot really doesn't do anything fancy with these plots, so there's probably no Violin-specific magic going on.

@GrimmSnark
Copy link
Author

Hello,

I am not really sure that it is a scatterplot issue. I have done a little more digging and I think it is caused by the use of violin as a class.

Using violin plot normally, ie vH = violinplot([rand(1,10)]); sets both vH.ScatterPlot.MarkerFaceColor and vH.ScatterPlot.CData to be a 1x3 RGB array of the default colour.

If I then try and modify the individual colours as I would in a normal scatter plot by vH.ScatterPlot.CData = rand(10,3); or
set(vH.ScatterPlot, 'CData', rand(10,3)); the values within the structure change but I get no change in the plot.

However, if I set a debug stop in violin at 241 and then try to modify the the CData, it works as normal and appearance changes.

But once the violin script reaches 397, i.e. after the display settings (set.ViolinColor) have been run then I am unable to affect the point colours by addressing CData.

At this point I am just getting the point X/Y coordinates by calling vH.ScatterPlot.XData and vH.ScatterPlot.YData and replotting the points with the appropriate colours after the violin plot call.

Anyway, mostly detailing this for anyone who wants to try and do what I am trying to do as well.

Michael

@bastibe
Copy link
Owner

bastibe commented Aug 12, 2022

If that's true, please take it up with the Mathworks tech support. CData should definitely change the scatter plot's colors.

(I'm not saying this as a flippant remark. Their tech support is often very responsive and helpful in issues like these.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants