Connecting points of a scatter plot with a line

7 views (last 30 days)
I am using the plotSpread function to to plot my data with categorical x axis (fig(1)). In order to see the changes of a point in the plot from the first stage to the next (NREM to Wake), I want to connect them with a line.
How can I plot the lines such that they connect all points in the two clusters? The jitter causes only the y axis coordinates to be connected, and not the actual points. I use the following loop to plot this:
%Plotting the data
nrem_rgs=Pyr_RGS_Unit_Wise_Data(:,3);
wake_rgs=Pyr_RGS_Unit_Wise_Data(:,6);
both=[nrem_rgs wake_rgs];
plotSpread(both,'xNames',{'NREM','Wake'},'distributionColors',{[0.4 .4 1],[0.2 0.2 .6]}, ...
'yLabel','Firing Rate Across Study Day')
% Loop for line connections
for k = 1 : size(nrem_rgs, 1)
plot([nrem_rgs(k), wake_rgs(k)],...
'rs-', 'MarkerSize', 5);
hold on
end
nrem_rgs and wake_rgs are of size (87,1)
I have read similiar questions but their solutions don't seem to work well for me.Thank you for your help!
  5 Comments
dpb
dpb on 5 Jul 2021
So, save the line handles (if the function returns them) when you plot (or retrieve them from the axes 'Children' property if it doesn't) and read those and use them instead of the raw data.
Or, if the function will return the jittered data as well, save and use it when create the plot first time.
I presume you would get a unique set every time you execute the function (that it doesn't internally reset the seed to be reproducible).

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!