Azzera filtri
Azzera filtri

Unable to change the height of the barh.

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Star Strider
Star Strider il 27 Lug 2023
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 Commenti
Aksh Chordia
Aksh Chordia il 27 Lug 2023
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 il 27 Lug 2023
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'
.

Accedi per commentare.

Più risposte (0)

Tag

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by