I am trying to save a plot as a graphics file. This works in general, but not correctly when I resize the plot.
The code I have written loads the data to be plotted from separate files, creates a plot and changes some of its properties before saving it as a graphics file. I copied the code below, except the part where the data is assigned to the variables and manipulated.
The part which I think may create the trouble is the command
with which I want to set the figure height to 250. So when I run the code, the figure window that is created looks like in the attached file window1.png. Resizing the figure obviously worked, but chart is not resized to fit into the smaller window.
Then when I drag the figure window by its title bar with the mouse, the chart changes size at once and looks like in window2.png. This is exactly what I want. Unfortunately, executing the command,
either before or after dragging the figure window, yields pngfile.png in both cases. The complete plot is saved (unlike shown in the figure window before moving it), but it has the standard height, not as depicted in window2.png.
I have used the command
300 203 560 417
for the originally created figure window (no idea where the 417 comes from), and
308 208 560 250
after dragging the window, which what I expect. The problem is that the saved png file has not the right aspect ratio and seems to be entirely unaffected by the 250 pixel height.
Does anyone have an idea why that is and how to fix it?
% [part that loads data to the variables i1, i2, i3 and c1, c2, c3]
[AX,Ha,Hb]=plotyy([tmin tmax],[0 0], [tmin tmax],[0 0]);
set(gcf,'position',[get(gcf,'position')(1:3) 250]); % this is where the plot is resized
set(AX,'position',[0.12 0.17 0.76 0.7]); % axes are set so that the labels and caption fit into the plot