1

I want to make a plot in Matlab which is twice as tall as it is long. I tried following the advice of this question using Position and PaperPositionMode, like so:

figure
set(gcf,'PaperPositionMode','auto');
set(gcf, 'Position', [0 0 100 200]);
barh(1:20);
print('test', '-dpng');

Annoyingly, this resizes the paper size but not the plot, as below.

a large plot on undersized paper

Is there any way to make a graph with specified width and height? I'm running this on a headless server so clicking and dragging, or any other GUI-specific solutions, aren't an option. Obviously I don't actually want a 100x200 plot, I just wanted to make the figure small enough to fit nicely into the question.

Community
  • 1
  • 1
rmccloskey
  • 482
  • 5
  • 14

2 Answers2

1

You might try setting the paper size and units. There's a similar question on Mathworks. Relevant content:

set(0,'defaultfigurepaperunits','inches');
set(0,'defaultfigurepaperorientation','landscape');
set(0,'defaultfigurepapersize',[8.5 11]);
set(0,'defaultfigurepaperposition',[.25 .25 [8.5 11]-0.5]);

where set(0, ...) sets the root graphics system values. You could also use your figure instead. Hope this helps.

Travis
  • 1,463
  • 11
  • 12
0

Alternative approach reference the documentation for figure(). Uses the units & outerposition properties.

figure('units','normalized','outerposition',[0 0 1 1])

See also the position property for another approach.

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41