Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Outer position - graphs resizing

Subject: Outer position - graphs resizing

From: Luca Zanotti Fragonara

Date: 18 Nov, 2008 15:53:02

Message: 1 of 13

Hello,
I need to modify the size of the graph that I'm plotting. I'm trying to find a property values or something like that, so that I can resize my figure. The problem is that I've also the legend, and I obtain a graph too little in comparison to the legend. I need to increase the outer position in the figure and implementing the resizing in a m file, because I've to enlarge all the graphs that I need to plot.

Any suggestions?

Thanks.

Best regards,

Luca

Subject: Outer position - graphs resizing

From: Husam Aldahiyat

Date: 18 Nov, 2008 16:37:02

Message: 2 of 13

Before the plotting command is issued, create your own figure on which the plot will be held.
You an do this via FIGURE command, like this:

figure('units','normalized','position',[a b c d])
plot(stuff)

Change c and d as preferred.
Hope this is what you asked about.

Subject: Outer position - graphs resizing

From: Luca Zanotti Fragonara

Date: 18 Nov, 2008 18:07:01

Message: 3 of 13

Thank you very much. Yes, I was thinking that there was a command within plot, instead I should use figure.

Thank you again.

Luca

"Husam Aldahiyat" <numandina@gmail.com> wrote in message <gfuqve$1u2$1@fred.mathworks.com>...
> Before the plotting command is issued, create your own figure on which the plot will be held.
> You an do this via FIGURE command, like this:
>
> figure('units','normalized','position',[a b c d])
> plot(stuff)
>
> Change c and d as preferred.
> Hope this is what you asked about.

Subject: Outer position - graphs resizing

From: Luca Zanotti Fragonara

Date: 18 Nov, 2008 20:13:02

Message: 4 of 13

Okay, now, I've another problem of the same nature. Now I visualize the figure big as I want, but when I perform saveas, the program saves the figures in the original wrong size.
I'm using this code:


h=figure('units','centimeters','position',[10 5 20 11]);
plot(various...);
%........various graphics sets
 saveas(h,['Pictures\',jobname,'.jpg']);


I don't understand why it saves me with a size different from the one that I've set with 'position'.

If I use this code:
figure('units','centimeters','position',[10 5 20 11]);
h=plot(various...);
%........various graphics sets
 saveas(h,['Pictures\',jobname,'.jpg']);

I receive an error of this kind:

??? Operands to the || and && operators must be convertible to logical scalar values.

Error in ==> saveas at 64
    while ~isfigure(h) && ~isempty(h)

Error in ==> plotsdir at 74
   saveas(h,['Pictures\',jobname,'.jpg']);

Subject: Outer position - graphs resizing

From: Ashish Uthama

Date: 18 Nov, 2008 20:32:52

Message: 5 of 13

On Tue, 18 Nov 2008 15:13:02 -0500, Luca Zanotti Fragonara
<Luca_Zanotti@libero.it> wrote:
> If I use this code:
> figure('units','centimeters','position',[10 5 20 11]);
> h=plot(various...);
> %........various graphics sets
> saveas(h,['Pictures\',jobname,'.jpg']);
>
> I receive an error of this kind:
>
> ??? Operands to the || and && operators must be convertible to logical
> scalar values.
>
> Error in ==> saveas at 64
> while ~isfigure(h) && ~isempty(h)
>
> Error in ==> plotsdir at 74
> saveas(h,['Pictures\',jobname,'.jpg']);
>
>


Luca,

Could you give us some exact steps which caused the above error?
It would also be important to mention the MATLAB version and the OS.

This works fine on R2008b, win32.

figure('units','centimeters','position',[10 5 20 11]);
h=plot(1:10)
saveas(h,'plot10.jpg');

Ashish

Subject: Outer position - graphs resizing

From: Luca Zanotti Fragonara

Date: 18 Nov, 2008 21:00:20

Message: 6 of 13

I use Matlab R2008a, winXP 32. If I plot just one series of data I never had problems, but when I've started to plot more series in the same graphs I started to receive that error. It's strange, because the plot command works perfectly.

h=figure('units','centimeters','position',[10 5 20 11])
plot(DT(1:lim(1)),Z(1,1:lim(1)),'s-',DT(1:lim(2)),Z(2,1:lim(2)),'s-',DT(1:lim(3)),Z(3,1:lim(3)),'s-',...
     DT(1:lim(4)),Z(4,1:lim(4)),'s-',DT(1:lim(5)),Z(5,1:lim(5)),'s-',DT(1:lim(6)),Z(6,1:lim(6)),'s-',...
     DT(1:lim(7)),Z(7,1:lim(7)),'s-','LineWidth',1,'MarkerSize',5);
     ntitle=['\fontsize{12}\bfTensione assiale - gradiente termico (elem. ',num2str(aa(i)),')'];
     title(ntitle);
     YTick=((round(YLim(1)/10))-1)*10:10:(round(YLim(2)/10))*10;
     set(gca,'YLim',YLim,'YTick',YTick,'LineWidth',1,'OuterPosition',[0 0 1 1]);
     grid on
     legend(leg,'Location','EastOutside');
     xlabel('\bfGRADIENTE \DeltaT [?C]');ylabel('\bfTENSIONE ASSIALE [N/mm^2]');

   saveas(h,['Pictures\',jobname,'_',bb,'.jpg']);

Subject: Outer position - graphs resizing

From: Luca Zanotti Fragonara

Date: 18 Nov, 2008 21:05:05

Message: 7 of 13

If you try this code, you should receive the error as well:

figure('units','centimeters','position',[10 5 20 11]);
h=plot(1:10,1:10,3:6,3:6)
saveas(h,'plot10.jpg');

I think that it's not possible to use h=plot and than save when there is more than one series of data.
If you try:

h=figure('units','centimeters','position',[10 5 20 11]);
plot(1:10,1:10,3:6,3:6)
saveas(h,'plot10.jpg');

you can see that the jpg has different proportion than the figure.

Subject: Outer position - graphs resizing

From: Ashish Uthama

Date: 18 Nov, 2008 21:10:18

Message: 8 of 13

On Tue, 18 Nov 2008 16:00:20 -0500, Luca Zanotti Fragonara
<Luca_Zanotti@libero.it> wrote:

> I use Matlab R2008a, winXP 32. If I plot just one series of data I never
> had problems, but when I've started to plot more series in the same
> graphs I started to receive that error. It's strange, because the plot
> command works perfectly.
>
> h=figure('units','centimeters','position',[10 5 20 11])
> plot(DT(1:lim(1)),Z(1,1:lim(1)),'s-',DT(1:lim(2)),Z(2,1:lim(2)),'s-',DT(1:lim(3)),Z(3,1:lim(3)),'s-',...
> DT(1:lim(4)),Z(4,1:lim(4)),'s-',DT(1:lim(5)),Z(5,1:lim(5)),'s-',DT(1:lim(6)),Z(6,1:lim(6)),'s-',...
> DT(1:lim(7)),Z(7,1:lim(7)),'s-','LineWidth',1,'MarkerSize',5);
> ntitle=['\fontsize{12}\bfTensione assiale - gradiente termico
> (elem. ',num2str(aa(i)),')'];
> title(ntitle);
> YTick=((round(YLim(1)/10))-1)*10:10:(round(YLim(2)/10))*10;
> set(gca,'YLim',YLim,'YTick',YTick,'LineWidth',1,'OuterPosition',[0
> 0 1 1]);
> grid on
> legend(leg,'Location','EastOutside');
> xlabel('\bfGRADIENTE \DeltaT [?C]');ylabel('\bfTENSIONE ASSIALE
> [N/mm^2]');
>
> saveas(h,['Pictures\',jobname,'_',bb,'.jpg']);
>


Luca,
Could you post code that we can run? You might think of using RAND or EYE
for sample data.
I tried to reproduce the error on R2008a/win32 with multiple plots but
with no success.
Ashish

Subject: Outer position - graphs resizing

From: Ashish Uthama

Date: 18 Nov, 2008 21:24:31

Message: 9 of 13

On Tue, 18 Nov 2008 16:05:05 -0500, Luca Zanotti Fragonara
<Luca_Zanotti@libero.it> wrote:

> If you try this code, you should receive the error as well:
>
> figure('units','centimeters','position',[10 5 20 11]);
> h=plot(1:10,1:10,3:6,3:6)
> saveas(h,'plot10.jpg');
>
> I think that it's not possible to use h=plot and than save when there is
> more than one series of data.
> If you try:
>
> h=figure('units','centimeters','position',[10 5 20 11]);
> plot(1:10,1:10,3:6,3:6)
> saveas(h,'plot10.jpg');
>
> you can see that the jpg has different proportion than the figure.


Thanks Luca.

As you probably noticed, h is an array of handles. The doc mentions that
the function expects a 'handle', unfortunately the error message is not
really helpful to indicate this.

Regarding proportion, the doc says:

"Use File ?> Save As on the figure window menu to access the Save As
dialog, in which you can select a graphics format. For details, see
Exporting in a Specific Graphics Format in the MATLAB Graphics
documentation. Note that sizes of files written to image formats by this
GUI and by saveas can differ, due to disparate resolution settings."

I used the GUI menu option (File->Save As) and the proportion is preserved.
If you are specifically looking for a command line option, maybe the PRINT
function has an option to preserve the proportion?

Subject: Outer position - graphs resizing

From: Luca Zanotti Fragonara

Date: 18 Nov, 2008 21:25:06

Message: 10 of 13

This should run:



clear;clc;
%[T,DT,C]=wloadstep();
%[node,elem,ncase,jobname]=varaxial();
DT=[0:25:200];
T=[20:30:200];
jobname=['analysisA'];

%Save picture, NO if 0, YES if 1.
sp=1;

%3D plot, NO if 0, YES if 1.
td=0;

aa=477;
%aa=input('Element Number [num]:');
bb= ['SDIR_',jobname,'_',num2str(aa)];
%filename=['Solutions\',bb,'.prn'];
%fin=fopen(filename,'rt');
%A=textscan(fin,'%*f %f %f %f %f %f %f %f','endofline','\n','Headerlines',1);
%fclose(fin);
%Z=[A{:}]'.*1e-6;
Z=rand(7,9)
s=size(Z);
for j=1:s(1);
    for k=1:s(2);
        if abs(Z(j,k))<0.000001;
            Z(j,k)=0;
        end
    end
end
f=num2str(T');
for k=1:length(f);
leg(k,:)=['T_m=',f(k,:),' ?C'];
end
lim=sum(sign(Z'));


%Y-Axis limits:



%Plot the results (3D plot):

figure('units','centimeters','position',[10 5 20 11])
if td==1;
[X,Y]=meshgrid(min(DT):30:max(DT),min(T):30:max(T));
mesh(X,Y,Z);
ntitle=['\fontsize{12}\bfTensione assiale - gradiente termico (elem. ',num2str(aa),')'];
title(ntitle);
set(gca,'Xtick',DT,'YTick',T);
xlabel('\bfGRADIENTE \DeltaT [?C]');ylabel('\bfTEMPERATURA [?C]');
zname=['\bfTENSIONE ASSIALE ',num2str(aa(i)),' [N/mm2]'];
zlabel(zname);

%Plot results (2D plot):
else h=plot(DT(1:lim(1)),Z(1,1:lim(1)),'s-',DT(1:lim(2)),Z(2,1:lim(2)),'s-',DT(1:lim(3)),Z(3,1:lim(3)),'s-',...
     DT(1:lim(4)),Z(4,1:lim(4)),'s-',DT(1:lim(5)),Z(5,1:lim(5)),'s-',DT(1:lim(6)),Z(6,1:lim(6)),'s-',...
     DT(1:lim(7)),Z(7,1:lim(7)),'s-','LineWidth',1,'MarkerSize',5);
     ntitle=['\fontsize{12}\bfTensione assiale - gradiente termico (elem. ',num2str(aa),')'];
     title(ntitle);
     set(gca,'LineWidth',1,'OuterPosition',[0 0 1 1]);
     grid on
     legend(leg,'Location','EastOutside');
     xlabel('\bfGRADIENTE \DeltaT [?C]');ylabel('\bfTENSIONE ASSIALE [N/mm^2]');
end

%Save figure to:
if sp==1;
   saveas(h,['Pictures\',jobname,'_',bb,'.tiff']);
end

Subject: Outer position - graphs resizing

From: Luca Zanotti Fragonara

Date: 18 Nov, 2008 21:34:02

Message: 11 of 13

Very nice. Where did you find this informations? It's two hours that I'm looking for something like that in the help!
Sadly I've already tried the print command, and I receive the same identical format problems...!
I know that with the GUI the proportion is mantained... But I've to save a lot of pictures, and so I'm looking for a command line options...

> "Use File ?> Save As on the figure window menu to access the Save As
> dialog, in which you can select a graphics format. For details, see
> Exporting in a Specific Graphics Format in the MATLAB Graphics
> documentation. Note that sizes of files written to image formats by this
> GUI and by saveas can differ, due to disparate resolution settings."
>
> I used the GUI menu option (File->Save As) and the proportion is preserved.
> If you are specifically looking for a command line option, maybe the PRINT
> function has an option to preserve the proportion?

Subject: Outer position - graphs resizing

From: Ashish Uthama

Date: 18 Nov, 2008 21:48:08

Message: 12 of 13

On Tue, 18 Nov 2008 16:34:02 -0500, Luca Zanotti Fragonara
<Luca_Zanotti@libero.it> wrote:

> Very nice. Where did you find this informations? It's two hours that I'm
> looking for something like that in the help!


:)
Thats from the first few lines of the doc help for SAVEAS

Please find more details online at:
     http://www.mathworks.com/access/helpdesk/help/techdoc/ref/saveas.html
Or please paste this in the MATLAB command window:
     web([docroot,'/techdoc/ref/saveas.html'])


> Sadly I've already tried the print command, and I receive the same
> identical format problems...!
> I know that with the GUI the proportion is mantained... But I've to save
> a lot of pictures, and so I'm looking for a command line options...

A hint on using PaperPositionMode from 'doc print' solves the issue with
PRINT:
(Search for 'Printing Figures at Screen Size' in the doc page for PRINT)

figure('units','centimeters','position',[10 5 20 11]);
plot(1:10,1:10,3:6,3:6)
set(gcf,'PaperPositionMode','auto')
print -f1 'printtest.jpg' -djpeg

Subject: Outer position - graphs resizing

From: Luca Zanotti Fragonara

Date: 18 Nov, 2008 21:57:02

Message: 13 of 13

Wow! Thank you very much! You saved me! It's funny because it is all the day that I've the solution in front of my eyes and I didn't see it. Sometimes it's true that we need new eye to solve the problem. Thank you again,

Regards,

Luca


"Ashish Uthama" <first.last@mathworks.com> wrote in message <op.ukt36i1ia5ziv5@uthamaa.dhcp.mathworks.com>...
> On Tue, 18 Nov 2008 16:34:02 -0500, Luca Zanotti Fragonara
> <Luca_Zanotti@libero.it> wrote:
>
> > Very nice. Where did you find this informations? It's two hours that I'm
> > looking for something like that in the help!
>
>
> :)
> Thats from the first few lines of the doc help for SAVEAS
>
> Please find more details online at:
> http://www.mathworks.com/access/helpdesk/help/techdoc/ref/saveas.html
> Or please paste this in the MATLAB command window:
> web([docroot,'/techdoc/ref/saveas.html'])
>
>
> > Sadly I've already tried the print command, and I receive the same
> > identical format problems...!
> > I know that with the GUI the proportion is mantained... But I've to save
> > a lot of pictures, and so I'm looking for a command line options...
>
> A hint on using PaperPositionMode from 'doc print' solves the issue with
> PRINT:
> (Search for 'Printing Figures at Screen Size' in the doc page for PRINT)
>
> figure('units','centimeters','position',[10 5 20 11]);
> plot(1:10,1:10,3:6,3:6)
> set(gcf,'PaperPositionMode','auto')
> print -f1 'printtest.jpg' -djpeg

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us