簡體   English   中英

如何在bar3中沿X軸的一側定位條?

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

我正在嘗試在背景圖像上使用 bar3 繪制條形圖。 雖然 bar3 命令能夠沿 Y 軸移動條形,但我不知道如何在 X 軸方向上移動條形。

這是我使用的示例,但仍然無法在 X 軸上移動條。

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

您有任何想法如何將條形移動到所需位置嗎? 謝謝!

您可以在創建條形后修改其 X 坐標,並將它們移動到您想要的任何位置。 下面的示例移動了示例中的 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