在下面的情节中
y = [2 2 3; 2 5 6; 2 8 9; 2 11 12];
bar(y)
我如何检索每个酒吧的位置,以便超级强加一个标记?
例如,我想把一颗星星放在第二组(第一组的第二杆)和第五杆(第二组的第二杆)的顶端。
我更喜欢一种解决方案,允许我修改创建后的情节。(见图)谢谢
发布于 2015-09-24 11:13:16
您可以使用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,'-*');
https://stackoverflow.com/questions/32755659
复制相似问题