How to have number as marker symbol in plot
38 views (last 30 days)
Show older comments
shirin
on 9 Feb 2014
Commented: Pannir Selvam Elamvazhuthi
on 29 Apr 2024
I'm trying to have a plot with number form 1 to 150 as a marker symbol.I have this but it doesn't work.please help
if true
% code
mark=zeros(1,class_length);
for i=1:class_length
mark(:,i)=i;
ma=num2str(mark);
malength=length(ma);
end
if mode==6 && colorflag==0
box on;
hold on;
for i=1:class_length
for p=1:malength
if classlabel(i)==p
plot(x(i),y(i),'Marker',mo(p),'MarkerSize',fontsize,'Color',colors(7));
end
end
end
hold off;
end
0 Comments
Accepted Answer
Walter Roberson
on 9 Feb 2014
You cannot create custom market symbols for use with plot(). My understanding is that the File Exchange contribution plt() allows you to define custom marker symbols.
However, what you should be doing in your situation is using text() instead of plot(). You are, after all, only putting up text and not drawing any lines.
By the way, with your existing code, why are you looping testing class labels one by one? And where did "mo" come from? Why do you take length(ma) and then throw away ma itself and throw away the length as well?
If you could create custom markers, then why not,
ma = cellstr(num2str(classlabel(:))); %num2str can process vector
for i=1:class_length
plot(x(i),y(i),'Marker',ma{i},'MarkerSize',fontsize,'Color',colors(7));
end
Though, as noted above, you cannot use custom markers: I am just illustrating that your code could have been more compact.
Suggested code replacement, for everything above that seems to have relevance:
if mode==6 && colorflag==0
box on;
text(x, y, cellstr(num2str(classlabel(:)))), 'FontSize', fontsize, 'Color', colors(7));
end
No loop needed.
3 Comments
Pannir Selvam Elamvazhuthi
on 29 Apr 2024
Thanks a lot for the 'text' code. I've used the following to get the numbers printed next to my markers positioned at x(i) and y(i):
fontsize=10;
no_of_numbers=10
for i=1:no_of_numbers
text(x(i)+0.05, y(i), cellstr(num2str(i)), 'FontSize', fontsize);
end
More Answers (1)
Mischa Kim
on 9 Feb 2014
Edited: Mischa Kim
on 9 Feb 2014
x = 0:1:10;
y = sin(x);
plot(x,y,'-r')
hold on
for ii = 1:length(x)
text(x(ii),y(ii),num2str(ii),'Color','r')
end
3 Comments
VIGNESH BALAJI
on 13 Jul 2023
This idea of plotting text in plot is very useful to number data and sorting them out. Thanks :)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!