Tags: below, code, doesnot, draws, figure, fit, larger, matlab, opens, programming, resize, thanthe, window

How to resize a figure

On Programmer » Matlab

11,172 words with 6 Comments; publish: Sun, 18 May 2008 19:55:00 GMT; (20062.50, « »)

I have the code below that draws a figure. However, the figure does

not fit into the figure window that opens up (figure is larger than

the window). When I resize the window, the figure resizes as well so

that it is again larger than the window. How can I fit this figure

into the window' I want to export the figure as a jpeg file. Thanks

for the help.

~Onur.

*********************

teta=[0.050 0.075 0.100 0.125 0.150 0.175 0.200 0.225 0.250];

pi6versuspistar=[8.490008308 8.155516522 7.986452014 7.909295007

7.870320782 7.87462387 7.905467759 7.956434739 8.019590727];

pi1versuspistar=[8.866190942 10.77142662 12.33018797 13.62504734

14.73479344 15.68525862 16.50421627 17.21859392 17.84473012];

[ax,pi6,pi1]=PLOTYY(teta,pi6versuspistar

,teta,pi1versuspistar);

set(ax(1),'fontsize',20, 'Ycolor','black');

set(ax(2),'fontsize',20,'Ycolor','black'

);

set(ax(1),'xtick',[0.05:0.05:0.25],'xlim',[0.05 0.25]);

set(ax(2),'xtick',[0.05:0.1:0.5],'xlim',[0.05 0.25]);

set(get(ax(1),'Ylabel'),'String','I_f

(%)','color','black','fontsize',20,'line

width',2);

set(get(ax(2),'Ylabel'),'String','I_{no}

(%)','color','black','fontsize',20,'line

width',2);

set(ax(1), 'ylim', [7.8 8.5], 'ytick', 7.8:0.1:8.5, 'Ycolor',

'black')

set(ax(2), 'ylim', [8 18], 'ytick', 8:1:18, 'Ycolor', 'black')

set(pi6, 'linestyle', '-',

'linewidth',2,'marker','*','markersize',

10,'color', 'black')

set(pi1, 'linestyle', '-','linewidth',2

,'marker','^','markersize',10,'color', 'black')

xlabel('Rate, \theta','fontsize',20);

legend(ax(1), 'I_f',2);

hold on;

legend(ax(2), 'I_{no}');

set(legend(ax(2)), 'color', 'w');

All Comments

Leave a comment...

  • 6 Comments
    • Can anyone help?

      Onur wrote:

      >

      > I have the code below that draws a figure. However, the figure does

      > not fit into the figure window that opens up (figure is larger than

      > the window). When I resize the window, the figure resizes as well

      > so

      > that it is again larger than the window. How can I fit this figure

      > into the window' I want to export the figure as a jpeg file.

      > Thanks

      > for the help.

      > ~Onur.

      > *********************

      > teta=[0.050 0.075 0.100 0.125 0.150 0.175 0.200 0.225 0.250];

      > pi6versuspistar=[8.490008308 8.155516522 7.986452014 7.909295007

      > 7.870320782 7.87462387 7.905467759 7.956434739 8.019590727];

      > pi1versuspistar=[8.866190942 10.77142662 12.33018797 13.62504734

      > 14.73479344 15.68525862 16.50421627 17.21859392 17.84473012];

      > [ax,pi6,pi1]=PLOTYY(teta,pi6versuspistar

      ,teta,pi1versuspistar);

      > set(ax(1),'fontsize',20, 'Ycolor','black');

      > set(ax(2),'fontsize',20,'Ycolor','black'

      );

      > set(ax(1),'xtick',[0.05:0.05:0.25],'xlim',[0.05 0.25]);

      > set(ax(2),'xtick',[0.05:0.1:0.5],'xlim',[0.05 0.25]);

      > set(get(ax(1),'Ylabel'),'String','I_f

      > (%)','color','black','fontsize',20,'line

      width',2);

      > set(get(ax(2),'Ylabel'),'String','I_{no}

      > (%)','color','black','fontsize',20,'line

      width',2);

      > set(ax(1), 'ylim', [7.8 8.5], 'ytick', 7.8:0.1:8.5, 'Ycolor',

      > 'black')

      > set(ax(2), 'ylim', [8 18], 'ytick', 8:1:18, 'Ycolor', 'black')

      > set(pi6, 'linestyle', '-',

      > 'linewidth',2,'marker','*','markersize',

      10,'color', 'black')

      > set(pi1, 'linestyle', '-','linewidth',2

      > ,'marker','^','markersize',10,'color', 'black')

      > xlabel('Rate, \theta','fontsize',20);

      > legend(ax(1), 'I_f',2);

      > hold on;

      > legend(ax(2), 'I_{no}');

      > set(legend(ax(2)), 'color', 'w');

      #1; Sun, 18 May 2008 19:57:00 GMT
    • Hi,

      you can set the postion of the figure with the following command:

      set(gcf,'position',[Xo Yo Widht Height])

      for example:

      set(gcf,'position',[100 100 300 300])

      You can export the figure in jpeg using the file menu "export..."

      By

      Claudio Gambelli

      http://www.gambelli.org

      Onur ha scritto:

      > Can anyone help?

      > Onur wrote:

      #2; Sun, 18 May 2008 19:58:00 GMT
    • Thanks guys but when I use this command, the size of the figure

      window changes as well as the size of the figure itself. In other

      words, the figure becomes larger when the figure window becomes

      larger. This is not what I want. I want the figure window to become

      larger WHILE the figure stay at its original size. Can I do this'

      Thanks for any help in advance.

      Claudio Gambelli wrote:

      >

      > Hi,

      > you can set the postion of the figure with the following command:

      > set(gcf,'position',[Xo Yo Widht Height])

      > for example:

      > set(gcf,'position',[100 100 300 300])

      > You can export the figure in jpeg using the file menu "export..."

      > By

      > Claudio Gambelli

      > <http://www.gambelli.org>

      >

      > Onur ha scritto:

      >

      figure

      > does

      larger

      > than

      as

      > well

      this

      > figure

      file.

      0.250];

      > 7.909295007

      8.019590727];

      > 13.62504734

      17.84473012];

      [ax,pi6,pi1]=PLOTYY(teta,pi6versuspistar

      ,teta,pi1versuspistar);

      'Ycolor',

      'black')

      'black')

      >

      #3; Sun, 18 May 2008 19:59:00 GMT
    • Can anyone help'

      Onur wrote:

      >

      > Thanks guys but when I use this command, the size of the figure

      > window changes as well as the size of the figure itself. In other

      > words, the figure becomes larger when the figure window becomes

      > larger. This is not what I want. I want the figure window to become

      > larger WHILE the figure stay at its original size. Can I do this'

      > Thanks for any help in advance.

      > Claudio Gambelli wrote:

      command:

      "export..."

      the

      > figure

      is

      > larger

      > resizes

      > as

      > this

      jpeg

      > file.

      > 0.250];

      > 8.019590727];

      > 17.84473012];

      > [ax,pi6,pi1]=PLOTYY(teta,pi6versuspistar

      ,teta,pi1versuspistar);

      0.25]);

      > 'Ycolor',

      > 'black')

      > 'black')

      #4; Sun, 18 May 2008 20:00:00 GMT
    • Top-posting repaired.

      Onur wrote:

      > Claudio Gambelli wrote:

      > Thanks guys but when I use this command, the size of the figure

      > window changes as well as the size of the figure itself. In other

      > words, the figure becomes larger when the figure window becomes

      > larger. This is not what I want. I want the figure window to become

      > larger WHILE the figure stay at its original size. Can I do this'

      The confusion was with terminology. In Matlab, "figure"

      is the same as "figure window". The graph inside the

      figure is an "axes" object.

      The answer to your question is yes, by manipulating the

      'position' property of the axes at the same time as the

      figure. Make sure the position of the axes is in absolute

      units, pixels for instance:

      set(gca, 'units', 'pixels');

      p_ax = get(gca, 'position'); % Save size and location of axes

      set(gcf, 'posiiton', [100 100 300 300]); % Resize figure

      set(gca, 'position', p_ax); % Restore size of axes

      - Randy

      #5; Sun, 18 May 2008 20:01:00 GMT
    • Thank you so much!!

      nox wrote:

      >

      > oops...I forgot a line ^^

      > here is the right code :

      > teta=[0.050 0.075 0.100 0.125 0.150 0.175 0.200 0.225 0.250];

      > pi6versuspistar=[8.490008308 8.155516522 7.986452014 7.909295007

      > 7.870320782 7.87462387 7.905467759 7.956434739 8.019590727];

      > pi1versuspistar=[8.866190942 10.77142662 12.33018797 13.62504734

      > 14.73479344 15.68525862 16.50421627 17.21859392 17.84473012];

      > [ax,pi6,pi1]=PLOTYY(teta,pi6versuspistar

      ,teta,pi1versuspistar);

      > set(ax(1),'fontsize',20, 'Ycolor','black');

      > set(ax(2),'fontsize',20,'Ycolor','black'

      );

      > set(ax(1),'xtick',[0.05:0.05:0.25],'xlim',[0.05 0.25]);

      > set(ax(2),'xtick',[0.05:0.1:0.5],'xlim',[0.05 0.25]);

      > set(get(ax(1),'Ylabel'),'String','I_f

      > (%)','color','black','fontsize',20,'line

      width',2);

      > set(get(ax(2),'Ylabel'),'String','I_{no}

      > (%)','color','black','fontsize',20,'line

      width',2);

      > set(ax(1), 'ylim', [7.8 8.5], 'ytick', 7.8:0.1:8.5, 'Ycolor',

      > 'black')

      > set(ax(2), 'ylim', [8 18], 'ytick', 8:1:18, 'Ycolor', 'black')

      > set(pi6, 'linestyle', '-',

      > 'linewidth',2,'marker','*','markersize',

      10,'color', 'black')

      > set(pi1, 'linestyle', '-','linewidth',2

      > ,'marker','^','markersize',10,'color', 'black')

      > xlabel('Rate, \theta','fontsize',20);

      > legend(ax(1), 'I_f',2);

      > hold on;

      > legend(ax(2), 'I_{no}');

      > set(legend(ax(2)), 'color', 'w');

      > P1 = get(gcf,'Position');

      > set(ax(1),'Units','pixel');

      > set(ax(2),'Units','pixel');

      > P1a = get(ax(1),'Position');

      > NewPosition = [350 400 900 700];

      > set (gcf,'Position',NewPosition);

      > set(ax(1),'Position',P1a + [P1(1)- NewPosition(1)

      > P1(2)-NewPosition(2) 0 0]);

      > set(ax(2),'Position',P1a + [P1(1)- 350 P1(2)-400 0 0]);

      #6; Sun, 18 May 2008 20:02:00 GMT