位置条分组条形图matlab
position bars grouped bar plot matlab
在下图中
y = [2 2 3; 2 5 6; 2 8 9; 2 11 12];
bar(y)
如何检索每个条的位置以超级施加标记?
例如,我想在第 2 个(第一组的第 2 个柱)和第 5 个(第二组的第 2 个柱)柱的顶部放置一个星号。
我更喜欢一个允许我在创建后修改情节的解决方案..
(如图所示)
谢谢
您可以使用 Xdata 和 Ydata 来执行此操作:
y = [2 2 3; 2 5 6; 2 8 9; 2 11 12];
h=bar(y);
% getting xdata and ydata from second bar in each group
xdata= get (h(2),'XData');
ydata= get (h(2),'YData');
% plot a * on second bar from second group
hold on;
offset=0.25;
plot(xdata(2),ydata(2)+offset,'-*');
如果你想在组的中心标记一个条,这个方法有效但是如果你想标记例如一个组中的第一个,你必须用 x 轴上的偏移值调整 * 的位置.
例如我想标记第二组的第三个小节:
y = [2 2 3; 2 5 6; 2 8 9; 2 11 12];
h=bar(y);
% getting xdata and ydata from second bar in each group
xdata= get (h(3),'XData');
ydata= get (h(3),'YData');
% plot a * on second bar from second group
hold on;
offset=0.25;
xoffset = 0.23; % manual set of get from properties of bar handle
plot(xdata(2)+xoffset,ydata(2)+offset,'-*');
在下图中
y = [2 2 3; 2 5 6; 2 8 9; 2 11 12];
bar(y)
如何检索每个条的位置以超级施加标记?
例如,我想在第 2 个(第一组的第 2 个柱)和第 5 个(第二组的第 2 个柱)柱的顶部放置一个星号。
我更喜欢一个允许我在创建后修改情节的解决方案.. (如图所示) 谢谢
您可以使用 Xdata 和 Ydata 来执行此操作:
y = [2 2 3; 2 5 6; 2 8 9; 2 11 12];
h=bar(y);
% getting xdata and ydata from second bar in each group
xdata= get (h(2),'XData');
ydata= get (h(2),'YData');
% plot a * on second bar from second group
hold on;
offset=0.25;
plot(xdata(2),ydata(2)+offset,'-*');
如果你想在组的中心标记一个条,这个方法有效但是如果你想标记例如一个组中的第一个,你必须用 x 轴上的偏移值调整 * 的位置.
例如我想标记第二组的第三个小节:
y = [2 2 3; 2 5 6; 2 8 9; 2 11 12];
h=bar(y);
% getting xdata and ydata from second bar in each group
xdata= get (h(3),'XData');
ydata= get (h(3),'YData');
% plot a * on second bar from second group
hold on;
offset=0.25;
xoffset = 0.23; % manual set of get from properties of bar handle
plot(xdata(2)+xoffset,ydata(2)+offset,'-*');