[英]Manipulating bar3 x-Axis values results into hollow barplot
I am setting up a bar3
plot and manipulated the X-Axis values since there is not a better way to do so. 由于没有更好的方法,因此我正在设置
bar3
图并操纵X轴值。 I went thorugh the code that Ander Biguri provided in his answer to this thread: How to set x and y values when using bar3 in Matlab? 我仔细研究了Ander Biguri在他对该线程的回答中提供的代码: 在Matlab中使用bar3时如何设置x和y值? .
。
It turns out that the X-Axis values are fine but the bars that are not located at the borders are archetype shaped. 事实证明,X轴值很好,但是不在边界处的条是原型形状的。 Probably it has to do with the data manipulation.
可能与数据操作有关。
Here is the corrisponding plot: 这是对应的图:
The data i used for this example: 我在此示例中使用的数据:
klasse_sig_a=[70 82 94 106 118 130 142 154 166 178 190];
klasse_sig_m=[-120 -102 -84 -66 -48 -30 -12 6 24 42 60];
RFMatrix=
[2 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 1 0 0;
0 0 0 0 2 0 0 0 0 2;
0 0 0 0 1 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 2 0 0 0 0 0;]
My code: 我的代码:
b=bar3(klasse_sig_m(2:end),RFMatrix,1);
xlabel('\sigma_a [MPa]')
ylabel('\sigma_m [MPa]')
zlabel('N [-]')
axis tight
for k = 1:length(b)
zdata = b(k).ZData;
b(k).CData = zdata;
b(k).FaceColor = 'interp';
end
Xdat=get(b,'XData');
diff=klasse_sig_a(2)-klasse_sig_a(1);
ONEMAT=ones(size(Xdat{1},1),size(Xdat{1},2)/2);
for ii=1:length(Xdat)
MAT=(Xdat{ii}-0.5);
if ii==1
MAT=MAT+[ONEMAT*min(klasse_sig_a) ONEMAT*(min(klasse_sig_a)+diff)-ii];
MAT_VOR=MAT(:,3:4);
else
MAT(:,1:2)=MAT_VOR;
MAT(:,3:4)=MAT(:,3:4)+ONEMAT*(min(klasse_sig_a)+ii*diff)-ii;
MAT_VOR=MAT(:,3:4);
end
Xdat{ii}=MAT;
set(b(ii),'XData',Xdat{ii});
end
set(gca,'XTick', klasse_sig_a(1:2:end))
set(gca,'YTick', klasse_sig_m(1:2:end))
I noticed that the non manipulated data always has a difference of 1 between left and right side of the matrix for each xdata{ii} 我注意到,对于每个xdata {ii},未经处理的数据在矩阵的左侧和右侧之间始终具有1的差异。
... ... ... ...
NaN NaN NaN NaN
NaN 0.5000 1.5000 NaN
0.5000 0.5000 1.5000 1.5000
0.5000 0.5000 1.5000 1.5000
NaN 0.5000 1.5000 NaN
NaN 0.5000 1.5000 NaN
NaN NaN NaN NaN
When setting my own data the difference becomes much bigger and the bar plots become hollow 设置自己的数据时,差异变得更大,条形图变得空洞
... ... ... ...
NaN 70 82 NaN
70 70 82 82
70 70 82 82
NaN 70 82 NaN
NaN 70 82 NaN
NaN NaN NaN NaN
How can I make the bars appear solid again? 如何使条再次显示为实心? I guess the data manipulation is erroneous.
我猜数据处理是错误的。 Thanks for any help!
谢谢你的帮助! Regards
问候
Note that the answer to the related question is specifically designed to deal with the case when your x values are sequential integers (ie the bin width is 1). 请注意, 相关问题的答案专门用于处理x值为连续整数(即bin宽度为1)的情况。 Your case is more general, with a bin width of 12. This requires slightly different logic.
您的情况更为笼统,箱宽为12。这需要稍微不同的逻辑。 I was able to get your desired results with the following code:
我能够通过以下代码获得您想要的结果:
b = bar3(klasse_sig_m(2:end), RFMatrix,1);
xlabel('\sigma_a [MPa]');
ylabel('\sigma_m [MPa]');
zlabel('N [-]');
axis tight;
for k = 1:length(b)
xData = b(k).XData;
zData = b(k).ZData;
set(b(k), 'XData', (xData-k).*diff(klasse_sig_a(k:(k+1)))+klasse_sig_a(k), ...
'CData', zData, 'FaceColor', 'interp');
end
set(gca, 'XTick', klasse_sig_a(1:2:end), 'YTick', klasse_sig_m(1:2:end));
And the plot: 和剧情:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.