Why the height of the bar3 decreases from original value as the size of the plot is varied?
5 ビュー (過去 30 日間)
古いコメントを表示
I am trying to get a 3D bar plot with some titled layout, however the height of the bars tend to decrease from its original values. I have attached the code below. please suggest how to correct this.
data_K=[0.8741,0.7742,0.7410,0.7488];
data_S=[0.9438,0.8490,0.7821,0.7330];
data_G=[0.8992,0.8496,0.8082,0.7685];
data_TS_F1=[data_K;data_S;data_G]*100;
f=figure('visible', 'on','GraphicsSmoothing','on','WindowStyle','docked');
grid on;
t1 = tiledlayout(1,1,'Padding','tight');
t1.Units = 'inches';
t1.OuterPosition = [0.40 0.05 2 1.6];
nexttile;
hp=bar3(data_TS_F1);
set(gca, 'XTick', 1:width(data_TS), 'XTickLabels', {'KNN','SVM','GNB'}, ...
'YTick', 1:4, 'YTickLabels', [1,3,6,12],'FontName',"Times New Roman","FontSize",12, 'ZTick',0:10:100);
ax=gca;
ax.FontWeight = 'bold';
set(hp(:),'facecolor',[0.745000000000000 0.745000000000000 1]);
xtickangle(0);
ytickangle(0);
4 件のコメント
dpb
2024 年 10 月 6 日
That is an optical delusion owing to the particular orientation and spacing of the limits for the x-axis xlim.
Look at the adjacent bar height GNB,1 on the back axis grid and you'll observe it is above 80 and the bar for SVM,1 is clearly higher than it is.
Try
xl=xlim;
xlim(xl+0.5*[1 -1]
and see if it doesn't look more better...
採用された回答
dpb
2024 年 10 月 6 日
data_K=[0.8741,0.7742,0.7410,0.7488];
data_S=[0.9438,0.8490,0.7821,0.7330];
data_G=[0.8992,0.8496,0.8082,0.7685];
data_TS_F1=[data_K;data_S;data_G]*100;
f=figure('visible', 'on','GraphicsSmoothing','on','WindowStyle','docked');
grid on;
t1 = tiledlayout(1,1,'Padding','tight');
t1.Units = 'inches';
t1.OuterPosition = [0.40 0.05 2 1.6];
t1.Units = 'normalized';
nexttile;
hp=bar3(data_TS_F1);
set(gca, 'XTick', 1:width(data_TS_F1), 'XTickLabels', {'KNN','SVM','GNB'}, ...
'YTick', 1:4, 'YTickLabels', [1,3,6,12],'FontName',"Times New Roman","FontSize",12, 'ZTick',0:10:100);
ax=gca;
ax.FontWeight = 'bold';
set(hp(:),'facecolor',[0.745000000000000 0.745000000000000 1]);
xtickangle(0);
ytickangle(0);
It's not clear what you're trying to do here, but the documentation link to the tiledlayout <position property> includes the following specific note:
"This property affects other properties, such as the Position property. If you change the units, then return the units to the default value after completing your computation to prevent affecting other functions that assume the default value."
Resetting the 'Position' property back to 'normalized' does change the behavior; the above may be more in keeping with your intent...
8 件のコメント
dpb
2024 年 10 月 6 日
編集済み: dpb
2024 年 10 月 6 日
If you look at the image @priyam kar posted of his original, the grid line at 80 extends almost directly to the back top edge of the SVM,1 bar, Bruno. @priyam kar was misinterpreting that as indicating the bar height was only 80; not projecting the bar in the represented 3D space. Hence, he thought the bar itself had been redrawn to be only ~80 units high, not recognizing the top of the bar itself when projected back to the axis would be/is really at the full height. As noted/agreed, it is a misreading of the plot created by the specific combination of data and location and chosen z axis ticks in confjunction with the default ylim and camera positions.
One could rotate and not change ylim and make it more clearly apparent where the bars are in space; I just shortened the y-axis first as being simpler to make the grid itelf be drawn closer to the bars so the location of the grid lines did fall closer to the actual bar edges.
I think it is a typical optical illusion trick; if one doesn't initially relate the line to the bar, then one will see the correct interpretation but if one ever does it the other way, then it can be difficult to change...
dpb
2024 年 10 月 6 日
編集済み: dpb
2024 年 10 月 7 日
data_K=[0.8741,0.7742,0.7410,0.7488];
data_S=[0.9438,0.8490,0.7821,0.7330];
data_G=[0.8992,0.8496,0.8082,0.7685];
data_TS_F1=[data_K;data_S;data_G].'*100;
grid on;
hp=bar3(data_TS_F1);
set(gca, 'XTick', 1:width(data_TS_F1), 'XTickLabels', {'KNN','SVM','GNB'}, ...
'YTick', 1:4, 'YTickLabels', [1,3,6,12],'FontName',"Times New Roman","FontSize",10, 'ZTick',0:10:100);
set(hp(:),'facecolor',[0.745000000000000 0.745000000000000 1]);
xtickangle(0);ytickangle(0);
z=data_S(1)*100;
line([2 2],[ylim],[z z],'linestyle','-','color','r')
line([xlim],[1 1],[z z],'linestyle','-','color','r')
Draws the projection of the height of Z(SVM,1) back to the axes grid that shows where the height projection is...I think in the original unaltered view the grid lines can make one easily misinterpret and it is difficult to really project where that intersection point is owing to the distance the grid lines are from the actual bar positions.
figure
hp=bar3(data_TS_F1);
set(gca, 'XTick', 1:width(data_TS_F1), 'XTickLabels', {'KNN','SVM','GNB'}, ...
'YTick', 1:4, 'YTickLabels', [1,3,6,12],'FontName',"Times New Roman","FontSize",10, 'ZTick',0:10:100);
set(hp(:),'facecolor',[0.745000000000000 0.745000000000000 1]);
xtickangle(0);ytickangle(0);
z=data_S(1)*100;
line([2 2],[ylim],[z z],'linestyle','-','color','r')
line([xlim],[1 1],[z z],'linestyle','-','color','r')
hAx=gca;
hAx.CameraPosition=hAx.CameraPosition.*[1.35 0.5 0.4]; % and rotate some as well...
If you rotate it around to more nearly the yz projection one can see where the bar tops are in relation to the grid lines a little more clearly, perhaps.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Axis Labels についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!