Here's how to locate the center of each grouped bar and label them. It uses an undocumented property "XOffset". This was developed and tested in r2019a.
xCnt are the bar centers.
figure()
v = randi(20,12,3);
h = bar(v,.8);
xCnt = get(h(1),'XData') + cell2mat(get(h,'XOffset'));
xLab = repmat({'p1','p2','p3'},1,numel(xCnt)/3);
set(gca, 'XTick', sort(xCnt(:)), 'XTickLabel', xLab)
Alternatively, you could rotate the x tick labels
set(gca, 'XTick', sort(xCnt(:)), 'XTickLabel', xLab, 'xticklabelrotation', 90)
The best solution would be to use a legend
legend(h,{'p1','p2','p3'})
Best Answer