简体   繁体   English

如何在bar3中沿X轴的一侧定位条?

[英]How to position bars along side the X axis in bar3?

I am trying to plot bars using bar3 on a background image.我正在尝试在背景图像上使用 bar3 绘制条形图。 Although the bar3 command is able to move the bars alongside the Y-axis, I have no idea how to move the bars in the X-axis direction.虽然 bar3 命令能够沿 Y 轴移动条形,但我不知道如何在 X 轴方向上移动条形。

This is an example of what I use, but still cannot move the bars in the X-axis.这是我使用的示例,但仍然无法在 X 轴上移动条。

A = [10 5 20 8];
bar3(1:4, A)
xlabel('x'); ylabel('y');

Do you have any ideas how to move the bars to the desired position?您有任何想法如何将条形移动到所需位置吗? Thanks!谢谢!

You can modify the X coordinate of your bars after they have been created and move them where ever you want them.您可以在创建条形后修改其 X 坐标,并将它们移动到您想要的任何位置。 The example below moves the 4 bars in your example, output img shown below.下面的示例移动了示例中的 4 个条,输出 img 如下所示。

f = figure;
ax = axes ( 'parent', f );
A = [10 5 20 8];
h = bar3(ax, 1:4, A );
xlabel('x'); 
ylabel('y');
% create some new positions for the xdata
index = randperm(4);
% the xdata is blocks on 6x4 coordinates
start = 1;
for ii=1:4
  finish = start+5;
  % for each block of data update the x co-ordinate
  %   this will "move" if along the x-axis
  h.XData(start:finish,:)=h.XData(start:finish,:)+index(ii);
  start = finish+1;
end
% Update the xlim of the axes to display them
ax.XLim = [0 5];

更新柱状图位置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM