Violinplot-Matlab icon indicating copy to clipboard operation
Violinplot-Matlab copied to clipboard

Colouring indivdual scatter points

Open GrimmSnark opened this issue 3 years ago • 5 comments

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

GrimmSnark avatar Jul 28 '22 10:07 GrimmSnark

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

bastibe avatar Jul 28 '22 11:07 bastibe

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

GrimmSnark avatar Jul 29 '22 08:07 GrimmSnark

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.

bastibe avatar Aug 02 '22 06:08 bastibe

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

GrimmSnark avatar Aug 03 '22 08:08 GrimmSnark

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.)

bastibe avatar Aug 12 '22 11:08 bastibe