displaying correct marker type using text command
Mostra commenti meno recenti
Hi, I am trying to plot 12 different markers for a long series of monthly reocord and wish to display the legend using 'text' command so I don't have a separate line of legend for each month. Instead the marker used for a month stays constant across all years. However, am not able to display a 'square' in text command despite using marker 's' in the plot and similarly for other markers. Please help. I tried using interpreter as latex and a '$' sign but got nothing. Here is a sample reproducible ex. I tried on Matlab 2015a.
Thanks in advance.
% sample code starts
temp=rand(14);
color_vector=zeros(14,3);
color_vector(13,:)=[1 0 0];
color_vector(14,:)=[1 0 0];
MarkerSet='so^d*+hvp><xso' % repeats after 12th entry
Present_year=2018
x_1=1.1;
x_2=1.5;
x_3=1.8;
y_top=2;
next_row_rel_loc=0.2;
font_val=10;
hold on
for ii = 1 : 3
plot(temp(ii,1:3),'marker',MarkerSet(ii),'markersize',10,'markeredgecolor',color_vector(ii,:),'LineStyle','none','linewidth',1)
end %ii
ylim([-2 2])
text(x_1,y_top, 'Month','FontSize',font_val) %Curr Year Prev Year')
text(x_2,y_top, num2str(Present_year),'FontSize',font_val)
text(x_3, y_top, 'Prev. Yr','FontSize',font_val)
text(x_1,y_top-next_row_rel_loc, 'Jan','FontSize',font_val)
text(x_2, y_top-next_row_rel_loc, '\color{red} s','FontSize',font_val)
text(x_3, y_top-next_row_rel_loc, '\color{black} s','FontSize',font_val)
text(x_1,y_top-next_row_rel_loc*2, 'Feb','FontSize',font_val)
text(x_2, y_top-next_row_rel_loc*2, '\color{red} o','FontSize',font_val)
text(x_3, y_top-next_row_rel_loc*2, '\color{black} o','FontSize',font_val)%,'interpreter', 'latex'
%end of sample code
Risposta accettata
Più risposte (1)
Jan
il 31 Mag 2018
What exactly is your question?
I am not able to display a 'square' in text command despite using marker 's' in the plot
Correct. There is no square character mentioned in doc text. This means, that you cannot use a TeX or LaTeX command to draw a square.
text(0.5, 0.5, '\square', 'InterPreter', 'TeX')
Warning: Error updating Text.
Character vector must have valid interpreter syntax:
\square
If you want a square, use the plot command and a marker instead of simulating it by a text. What is the problem with using legend?
3 Commenti
Walter Roberson
il 31 Mag 2018
\square requires LaTex AMS package, which is not included in MATLAB's LaTex. There is also \Square which is wasyssym package, also not included.
Munish Sikka
il 31 Mag 2018
Walter Roberson
il 31 Mag 2018
Example:
plot(rand(1,20), 'b*-');
hold on
plot(rand(1,20).^2, 'b^-');
plot(randn(1,20), 'k*-');
plot(randn(1,20).^2, 'k^-');
L(1) = plot(nan, nan, 'b-');
L(2) = plot(nan, nan, 'k-');
legend(L, {'2016', '2017'})
Categorie
Scopri di più su Line Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!