Borrar filtros
Borrar filtros

Why are the descriptive names of my boxchart categories not visible in my figure?

5 visualizaciones (últimos 30 días)
Hi all, I am trying to visualise ply thicknesses (in multiple composite samples) using boxchart(). I manage to show the boxes according to the ply numbers. However, I would like to mention the fibre orientation with the ply numbers as well. The (adapted, for readability) code I used so far is shown below. I also included the result I obtained.
My problem is that the y-axis do not show both the number and the orientation of the plies. I tried to follow the "Create Multiple Box Charts Using Positional Grouping Variable" example in the boxchart documentation, because this example shows the replacement of numbered axis-ticklabels to a descriptive label (just like I want my axis to be). It tells me to use categorical() to "replace" the plain ply numbers, after which I need to use boxchart. Although I think I applied this example correctly to my case and all intermediate steps look like they were executed as desired, the figure does not turn out as intended. Why are the descriptive names on the y-axis not visible in the figure?
table = array2table([nr t]; % A table containing the ply numbers (pnr) and their corresponding thicknesses (t). This outputs a table with many rows (the amount of samples with n plies) by 2 columns (pnr and t)
for i = 1:nplies
p_ors_str = string(sprintf('%02i: %i%c',nply(i),layup_weld(i),char(0176)))); % Describing the ply number with the corresponding orientation
end % Results in a nplies*1 string containing element similar to "01: 45°".
p_ors_cat = categorical(table.nr,1:nplies,p_ors_str); % Converting the ply numbers to a descriptive string in a categorical array
figure(1), clf(1), hold on
subplot(2,1,1), hold on % This method corresponds to the "boxchart(earthquakes.Month,earthquakes.EarthquakeMagnitude)"-command in the example
boxchart(table.pnr,table.t,'Orientation','Horizontal') % The boxes visualise the several measurements for every ply, showing ply numbers
ylabel('Ply number')
subplot(2,1,2), hold on % This method corresponds to the "boxchart(namedMonths,earthquakes.EarthquakeMagnitude)"-command in the example
boxchart(p_ors_str,table.t,'Orientation','Horizontal') % The boxes should visualise the same as before, but describing the ply number with their orientation
ylabel('Ply number and orientation')

Respuesta aceptada

Voss
Voss el 5 de Jun. de 2024
There are several typos in your (adapted) code. It would be better to share the actual code you're running that produces the problem, along with any data that is necessary to run it. You can upload m-files and mat-files using the paperclip icon.
Below I'm running an adapted version of your adapted code, based on random data, and the second plot does have the descriptive names on the y-axis, so I think we would need to have your actual code and data to figure out the problem.
nplies = 12;
nsamples = 100;
nr = randi(nplies,nsamples,1);
t = 110+100*rand(nsamples,1);
nply = randi(8,nplies,1);
layup_weld = randi([10 80],nplies,1);
T = array2table([nr t],'VariableNames',{'nr','t'}); % A table containing the ply numbers (pnr) and their corresponding thicknesses (t). This outputs a table with many rows (the amount of samples with n plies) by 2 columns (pnr and t)
p_ors_str = strings(1,nplies);
for i = 1:nplies
p_ors_str(i) = sprintf("%02i: %i%c",nply(i),layup_weld(i),char(0176)); % Describing the ply number with the corresponding orientation
end % Results in a nplies*1 string containing element similar to "01: 45°".
p_ors_cat = categorical(T.nr,1:nplies,p_ors_str); % Converting the ply numbers to a descriptive string in a categorical array
figure(1), clf(1)
subplot(2,1,1) % This method corresponds to the "boxchart(earthquakes.Month,earthquakes.EarthquakeMagnitude)"-command in the example
boxchart(T.nr,T.t,'Orientation','Horizontal') % The boxes visualise the several measurements for every ply, showing ply numbers
ylabel('Ply number')
subplot(2,1,2) % This method corresponds to the "boxchart(namedMonths,earthquakes.EarthquakeMagnitude)"-command in the example
boxchart(p_ors_cat,T.t,'Orientation','Horizontal') % The boxes should visualise the same as before, but describing the ply number with their orientation
ylabel('Ply number and orientation')
  4 comentarios
Monique Lamers
Monique Lamers el 7 de Jun. de 2024
Ah, I did not know that the LaTeX interpreter had struggles with that part. Thanks for the work-around suggestions!
Voss
Voss el 7 de Jun. de 2024
You're welcome!
It is strange because usually a warning for invalid interpreter syntax is issued and the text is rendered uninterpreted, but in this case the text just was not rendered at all.

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by