79313794

Date: 2024-12-28 12:48:38
Score: 0.5
Natty:
Report link

Here is a commented example similar to your case, with grouped bars:

[x, y] = ([1 2 5], [1  -5 6;3 -2 7;4  -3 8]);
h = bar(x, y);

txy = h.children.data;  // get bars raw coordinates
// tune x coordinates of labels inside groups
txy(:,1) = txy(:,1) + h.children.x_shift'(:) - h.children(1).bar_width/2;

// get Text height to tune y coordinates for labels below the bars (y<0)
th = xstringl(1,1,"8")(4);

// Display values
t = xstring(txy(:,1), txy(:,2) - th*(txy(:,2)<0), string(txy(:,2))+".0");

// reframe the plot to show the value for the highest bar
replot

Result:

enter image description here

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: S. Gougeon