Borrar filtros
Borrar filtros

How to get position of single box in grouped box chart on x-axis?

22 visualizaciones (últimos 30 días)
Vincent
Vincent el 16 de Feb. de 2021
Editada: Scott MacKenzie el 11 de Mayo de 2021
I would like to get the position of each single box on the x-axis I created with boxchart(). But the box chart object is grouped, so when I type XAxis.Categories I only get the two grouping categories even though it's actually 6 boxes.

Respuestas (1)

Scott MacKenzie
Scott MacKenzie el 11 de Mayo de 2021
Editada: Scott MacKenzie el 11 de Mayo de 2021
The use of grouped data changes the XData type to categorical for the BoxChart. Plus, there doesn't seem to be any BoxChart property that gives the x position of the group or the x-offset of the boxes within a group. I determined that the actual x positions of the groups are 1, 2, 3, etc., as they would be if the data were not categorical. Knowing this, I concocted a scheme to compute the x-position of each box, so that text annotations (or whatever) can be added. See below. This can probably be vectorized in some way, but I thought it might useful to post this in the present form.
set(groot, 'defaultTextHorizontalAlignment', 'center');
m = 3; % number of boxes per group
xGap = 1 / m;
grp = 1; % x position for 1st group
text(grp-xGap, 30, 'a1');
text(grp, 30, 'a2');
text(grp+xGap, 30, 'a3');
grp = 2; % x position for 2nd group
text(grp-xGap, 30, 'b1');
text(grp, 30, 'b2');
text(grp+xGap, 30, 'b3');

Categorías

Más información sobre Graphics Object Properties en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by