Boxplot multiline labels with latex interpreter
Afficher commentaires plus anciens
I am trying to plot a boxplot for data with two different lines for each label that are strings constructed from values of a matrix.
tol_r_f=[0 .2;0 .04;0 .03;.1 1];
tol_v_f=[.3 1;.09 .2;0 .07;1 10];
range={{[num2str(tol_r_f(1,1)) '$\leq ||\boldmath{r}_f|| \leq$' num2str(tol_r_f(1,2))];...
[num2str(tol_v_f(1,1)) '$\leq ||\boldmath{v}_f|| \leq$' num2str(tol_v_f(1,2))]},...
{[num2str(tol_r_f(2,1)) '$\leq ||\boldmath{r}_f|| \leq$' num2str(tol_r_f(2,2))];...
[num2str(tol_v_f(2,1)) '$\leq ||\boldmath{v}_f|| \leq$' num2str(tol_v_f(2,2))]},...
{[num2str(tol_r_f(3,1)) '$\leq ||\boldmath{r}_f|| \leq$' num2str(tol_r_f(3,2))];...
[num2str(tol_v_f(3,1)) '$\leq ||\boldmath{v}_f|| \leq$' num2str(tol_v_f(3,2))]},...
{[num2str(tol_r_f(4,1)) '$\leq ||\boldmath{r}_f|| \leq$' num2str(tol_r_f(4,2))];...
[num2str(tol_v_f(4,1)) '$\leq ||\boldmath{v}_f|| \leq$' num2str(tol_v_f(4,2))]}};
x_t1=rand(1,50)
g_t1=[zeros(1,10) ones(1,20) 2*ones(1,10) 3*ones(1,10)];
x_t2=rand(1,50)
g_t2=[zeros(1,10) ones(1,20) 2*ones(1,10) 3*ones(1,10)];
x_tf=rand(1,50)
g_tf=[zeros(1,10) ones(1,20) 2*ones(1,10) 3*ones(1,10)];
figure(1)
boxplot(x_t1,g_t1,'labels',range)
xlabel('Cluster Ranges','Interpreter','Latex')
ylabel('$\% t_1$','Interpreter','Latex')
figure(2)
boxplot(x_t2,g_t2,'labels',range)
xlabel('Cluster Ranges','Interpreter','Latex')
ylabel('$\% t_2$','Interpreter','Latex')
figure(3)
boxplot(x_tf,g_tf,'labels',range)
xlabel('Cluster Ranges','Interpreter','Latex')
ylabel('$\% t_f$','Interpreter','Latex')
3 commentaires
Walter Roberson
le 17 Juil 2022
You have four entries in range but there are only three unique g_tf entries. The number of unique group entries must match the number of entries in range.
Alessandro Maria Laspina
le 17 Juil 2022
tol_r_f=[0 .2;0 .04;0 .03;.1 1];
tol_v_f=[.3 1;.09 .2;0 .07;1 10];
range={{[num2str(tol_r_f(1,1)) '$\leq ||\boldmath{r}_f|| \leq$' num2str(tol_r_f(1,2))];...
[num2str(tol_v_f(1,1)) '$\leq ||\boldmath{v}_f|| \leq$' num2str(tol_v_f(1,2))]},...
{[num2str(tol_r_f(2,1)) '$\leq ||\boldmath{r}_f|| \leq$' num2str(tol_r_f(2,2))];...
[num2str(tol_v_f(2,1)) '$\leq ||\boldmath{v}_f|| \leq$' num2str(tol_v_f(2,2))]},...
{[num2str(tol_r_f(3,1)) '$\leq ||\boldmath{r}_f|| \leq$' num2str(tol_r_f(3,2))];...
[num2str(tol_v_f(3,1)) '$\leq ||\boldmath{v}_f|| \leq$' num2str(tol_v_f(3,2))]},...
{[num2str(tol_r_f(4,1)) '$\leq ||\boldmath{r}_f|| \leq$' num2str(tol_r_f(4,2))];...
[num2str(tol_v_f(4,1)) '$\leq ||\boldmath{v}_f|| \leq$' num2str(tol_v_f(4,2))]}};
x_t1=rand(1,50)
g_t1=[zeros(1,10) ones(1,20) 2*ones(1,10) 3*ones(1,10)];
x_t2=rand(1,50)
g_t2=[zeros(1,10) ones(1,20) 2*ones(1,10) 3*ones(1,10)];
x_tf=rand(1,50)
g_tf=[zeros(1,10) ones(1,20) 2*ones(1,10) 3*ones(1,10)];
figure(1)
Range1 = cellfun(@(C) C{1}, range, 'UniformOutput',false);
Range2 = cellfun(@(C) C{2}, range, 'UniformOutput',false);
Range = {Range1, Range2};
boxplot(x_t1, g_t1.', 'labels', Range)
xlabel('Cluster Ranges','Interpreter','Latex')
ylabel('$\% t_1$','Interpreter','Latex')
set(findobj(1, 'type', 'text'), 'interpreter', 'latex');
figure(2)
boxplot(x_t2, g_t2.', 'labels', Range)
xlabel('Cluster Ranges','Interpreter','Latex')
ylabel('$\% t_2$','Interpreter','Latex')
set(findobj(2, 'type', 'text'), 'interpreter', 'latex');
figure(3)
boxplot(x_tf, g_tf.', 'labels', Range)
xlabel('Cluster Ranges','Interpreter','Latex')
ylabel('$\% t_f$','Interpreter','Latex')
set(findobj(3, 'type', 'text'), 'interpreter', 'latex');
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Exploration and Visualization dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



