Unable to change the height of the barh.

2 次查看(过去 30 天)
I have a tiled layout wherein, of the tiles is like this.
The code looks like this:
y=[67 147-67 1073-147 3456-1073 5000-3456];
def=[1];
nexttile
d1=barh(def,y,3,'stacked');
axis ([0 5000 0 2]);
xlabel('Defect Size [Ohm]');
title('Defect 1 @ 100C');
set(gca,'ytick',[],'FontSize',30);
I am trying to reduce the height of the figure, but the position 'Position' is not working. Could you suggest any other way to do it.
Thank you
Aksh

采纳的回答

Star Strider
Star Strider 2023-7-27
The tiledlayout plots will not let you do that, however subplot will.
Try this —
figure
y=[67 147-67 1073-147 3456-1073 5000-3456];
def=[1];
subplot(1,1,1)
d1=barh(def,y,3,'stacked');
axis ([0 5000 0 2]);
xlabel('Defect Size [Ohm]');
title('Defect 1 @ 100C');
set(gca,'ytick',[],'FontSize',30);
figure
y=[67 147-67 1073-147 3456-1073 5000-3456];
def=[1];
subplot(1,1,1)
d1=barh(def,y,3,'stacked');
axis ([0 5000 0 2]);
xlabel('Defect Size [Ohm]');
title('Defect 1 @ 100C');
set(gca,'ytick',[],'FontSize',30);
pos = get(gca, 'Position');
set(gca,'Position',pos.*[1 1.25 1 0.25])
Experiment to get the result you want.
.
  2 个评论
Aksh Chordia
Aksh Chordia 2023-7-27
Thank you very much.
I was using subplot previously and then switched to the tiled layout because the former does not give an option for a global legend.
Is there some workaround? Can I still use tiled layout, because its legending is much simpler and elegant.
Star Strider
Star Strider 2023-7-27
You can use global legends with subplot similarly to the way you would create it in tiledlayout.
Try something like this —
x = 0:0.5:10;
y1 = randn(size(x,2),2);
y2 = randn(size(x,2),2);
y3 = randn(size(x,2),2);
figure
subplot(2,2,1)
plot(x,y1)
grid
hl = legend('y_1','y_2'); % Create Legend, Return Handle
subplot(2,2,2)
plot(x,y2)
grid
subplot(2,2,3)
plot(x,y3)
grid
subplot(2,2,4)
Ax = gca;
Ax.Visible = 0; % Make Axes Invisible
hl.Position = Ax.Position; % Use These Position Values For 'legend'
.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by