output matlab markers as part of a character string.

15 次查看(过去 30 天)
It's amazing that nobody has asked this before, but I'd like to insert the standard matlab plot markers---square, diamond, circle, etc---into a character string. Presumably this is possible?
For reasons too banal to explain, it's not easy for me to use the standard legend commands, and the quickest quick-dirty fix is to create my own, as annotations.
Thanks for any suggestions how to do this.
PS, I'm getting closer to doing this with unicode characters. Could anybody please tell me the matlab unicode character for an unfilled diamond? I've found circle (9711) and square (9744).
Thanks very much!

采纳的回答

Cindy Solomon
Cindy Solomon 2015-7-28
Hi Leo,
To add to Walter's comment, (if I understand what you are trying to do correctly), I would also recommend looking into the native2unicode function or the reverse (unicode2native). These combined with the char function can let you insert a variety of characters in as plot markers. For example:
%*** Create A Plot With NO Markers ***
x = 1:40;
y = rand( 1, 40 );
plot( x, y );
axis( [0.5, 40.5, -0.1, 1.1 ] );
%*** Add Filled Markers from 1 to 10 (u+2776 to u+277F) ***
for i = 1:10
nativeValue = char( hex2dec( '2776' ) + i - 1); %Native format (bit/byte arrangement)
unicodeValue = native2unicode( nativeValue, 'UTF-16' ); %Convert to Unicode 16 format
text( x( i + 20 ), y ( i + 20 ),... %Position of font character
unicodeValue,...
'FontSize',12,... %Set font size to 12
'HorizontalAlignment', 'Center',... %Center character on point
'VerticalAlignment', 'Middle' );
end
I apologize if I misunderstood your question, but hope this is helpful!
  1 个评论
Leo Simon
Leo Simon 2015-7-29
This is really great, thanks very much indeed. I have remaining two questions. First, how can I get the numbered balls to show up in a legend? The legend command thinks that stem is the only thing it has to report. Second, in the code below, I've modified your code to use stem. As you will see, I reduced the height of the y vector so that the top of the line didn't protrude into the blue circle. But I poorly eyeballed the value of offset in the code. If I could get the radius of the ball in figure coordinates. then I could use axxy2fixxy to get the length of the line exactly.
close all
x = 1:10;
y = rand( 1, 10 );
axis( [0.5, 10.5, -0.1, 1.1 ] );
offset = 0.06;
numInBall = @(i)native2unicode( char( hex2dec( '2776' )+i-1), 'UTF-16' );
hold on;
for i = 1:10
hT = text( x( i ), y ( i ), numInBall(i),...
'FontSize',20, 'Color','b', 'HorizontalAlignment', 'Center', 'VerticalAlignment', 'Middle' );
end
hS = stem( x, (y - offset) ,'Color','b','Marker','none');

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by