Is there a way of making a scatter plot where all the points are different markers and colours?
17 views (last 30 days)
Show older comments
Hi,
I am pretty much a beginner here. I am trying to make a scatter plot from data that are currently in an excel spreadsheet. I have 5 pairs of column (representing 5-years) with 6 rows in each (representing 6-months). The first column of each pair shows a temperature, and the second column precipitation. What I would like is to have the data from the 5 years represented by different colours, and at the same time, have a different markers for each months. So, one colour per year (total of 5 colours) and one marker per month (total of 6 different marker) Is this something that can be done easily? The only way I could do this with my limited knowledge of Matlab, would be to reorganize the data and do individual scatter plots with hold on hold off function. There must be an easier way...?
Thanks
2 Comments
Brendan Hamm
on 6 Aug 2015
Edited: Brendan Hamm
on 6 Aug 2015
The color can be done easily as the scatter() function takes this as an input argument. So if you have a vector representing the year of the corresponding data pass this in for the 4th input argument:
scatter(x,y,a,c)
A scatter plot will always plot the same markers though, so the easiest way here is to do this in a for loop with the hold on as you mention.
I would be happy to make an example of this if you mention how the data is store in MATLAB. Is it in a table, a matrix, several matrices? Are the dates represented as strings, vectors, datetimes or datenums? Which version of MATLAB are you using?
Ali
on 29 Oct 2017
if true
--------------------------------------------------- code start
This is an example for your case
Input is "Input_Data", two dimension matrix
Marker_Counter=1;
figure6=figure;
Markers = {'+','o','*','x','v','d','^','s','>','<'};
for i=1:10:size(Input_Data,1)
TPR=Input_Data(i:i+9,7);
FPR=Input_Data(i:i+9,8);
plot(FPR,TPR,strcat('-',Markers{Marker_Counter}));
Marker_Counter=Marker_Counter+1;
hold on
end
plot([0.5 1],[0.5 1],'--');
legend('Minpts = 100','Minpts = 200','Minpts = 300','Minpts = 400','Minpts = 500','Minpts = 600','Minpts = 700','Minpts = 800','Minpts = 900','Minpts = 1000','','Location','SouthEast');
xlabel('FPR or (1-Specificity)','FontSize',12,'FontWeight','bold'); ylabel('TPR or Spensitivity)','FontSize',12,'FontWeight','bold');
title('ROC Space');
close(gcf);
-------------------------------------------- code end
end
--------------------------------------- picture link preview

Accepted Answer
Walter Roberson
on 6 Aug 2015
scatter() only permits one color and one marker shape per call to scatter(). plot() permits one color and one marker shape per column of Y values. plot() can be automated a bit easier.
t = randn(5,6) + 18; %sample data
p = rand(5,6); %sample data
q = [num2cell(t(:)),num2cell(p(:))].';
M = 'os^vp'; %5
C = 'rgbckm'; %6
[A,B] = ndgrid(1:length(M),1:length(C));
plotspecs = cellstr([M(A(:)).',C(B(:)).']).';
q2 = [q; plotspecs];
plot(q2{:});
4 Comments
Walter Roberson
on 11 Aug 2015
That code cannot be generalized for using numeric colors, as plot() only accepts multiple color specifications in character form. To use numeric form, you need to omit the color specification and capture the plot handles and set() the information for them. But if you are going to do that you might as well set the marker information on the same time.
More Answers (1)
See Also
Categories
Find more on Scatter Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!