ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 10 Apr 2011 11:05:04 -0500Scaling of png from Matlabhttp://ask.sagemath.org/question/8040/scaling-of-png-from-matlab/Hi
I have been trying find a way to prevent or control scaling of generated png's in the sage notebook.
Sometimes I am using Matlab to generate graphs and it works fine, except that the image is scaled in the sage notebook. If I open the file in the cell folder then I can see that it is scaled, at least when I compare the output from the exact same code evaluated directly in Matlab.
Is there some way to control scaling in sage?
EDIT:
The problem is that the generated image from Matlab has a higher resolution than the image which is saved in the cell folder in the notebook.
It seems as if the image is first saved somewhere else, then scaled, and then saved in the cell folder.
So I am wondering if there is som global setting in sage which sets the scaling factor.
Example:
#auto
%matlab
clear;clc;clf;
h1 = [0.25 0.25 0.25 0.25]; % for n = 0,1,2,3
h2 = [1 -1]; % for n = 0,1
t=0:1:204;
x = randn(1,200);
hfig=figure(1); clf
plot(x)
hold on
plot(conv(x,h1),'r')
axis([1 500 -5 5])
hold on
plot(conv(x,h2),'g')
axis([1 50 -5 5])
legend('x','conv(x,h1)','conv(x,h2)', 'Location','NorthEastOutside')
print -dpng image.png
This code saves the produced plot in the current folder directly.
I know this is matlab code and not sage, but the same code produces a larger image (higher resolution) when evaluated directly in matlab, than it does when evaluated in matlab from the sage notebook.
Maybe I am mistaking about this, but these are the "symptoms" I'm experiencing here. Wed, 30 Mar 2011 23:06:22 -0500http://ask.sagemath.org/question/8040/scaling-of-png-from-matlab/Comment by kcrisman for <p>Hi</p>
<p>I have been trying find a way to prevent or control scaling of generated png's in the sage notebook.</p>
<p>Sometimes I am using Matlab to generate graphs and it works fine, except that the image is scaled in the sage notebook. If I open the file in the cell folder then I can see that it is scaled, at least when I compare the output from the exact same code evaluated directly in Matlab.</p>
<p>Is there some way to control scaling in sage?</p>
<p>EDIT:
The problem is that the generated image from Matlab has a higher resolution than the image which is saved in the cell folder in the notebook.
It seems as if the image is first saved somewhere else, then scaled, and then saved in the cell folder.
So I am wondering if there is som global setting in sage which sets the scaling factor.
Example:</p>
<pre><code>#auto
%matlab
clear;clc;clf;
h1 = [0.25 0.25 0.25 0.25]; % for n = 0,1,2,3
h2 = [1 -1]; % for n = 0,1
t=0:1:204;
x = randn(1,200);
hfig=figure(1); clf
plot(x)
hold on
plot(conv(x,h1),'r')
axis([1 500 -5 5])
hold on
plot(conv(x,h2),'g')
axis([1 50 -5 5])
legend('x','conv(x,h1)','conv(x,h2)', 'Location','NorthEastOutside')
print -dpng image.png
</code></pre>
<p>This code saves the produced plot in the current folder directly.</p>
<p>I know this is matlab code and not sage, but the same code produces a larger image (higher resolution) when evaluated directly in matlab, than it does when evaluated in matlab from the sage notebook.</p>
<p>Maybe I am mistaking about this, but these are the "symptoms" I'm experiencing here. </p>
http://ask.sagemath.org/question/8040/scaling-of-png-from-matlab/?comment=21894#post-id-21894Probably right. I've changed the title of the question to address this - hope nobody put in any hard links to the URL!Tue, 05 Apr 2011 09:07:29 -0500http://ask.sagemath.org/question/8040/scaling-of-png-from-matlab/?comment=21894#post-id-21894Comment by Kabi for <p>Hi</p>
<p>I have been trying find a way to prevent or control scaling of generated png's in the sage notebook.</p>
<p>Sometimes I am using Matlab to generate graphs and it works fine, except that the image is scaled in the sage notebook. If I open the file in the cell folder then I can see that it is scaled, at least when I compare the output from the exact same code evaluated directly in Matlab.</p>
<p>Is there some way to control scaling in sage?</p>
<p>EDIT:
The problem is that the generated image from Matlab has a higher resolution than the image which is saved in the cell folder in the notebook.
It seems as if the image is first saved somewhere else, then scaled, and then saved in the cell folder.
So I am wondering if there is som global setting in sage which sets the scaling factor.
Example:</p>
<pre><code>#auto
%matlab
clear;clc;clf;
h1 = [0.25 0.25 0.25 0.25]; % for n = 0,1,2,3
h2 = [1 -1]; % for n = 0,1
t=0:1:204;
x = randn(1,200);
hfig=figure(1); clf
plot(x)
hold on
plot(conv(x,h1),'r')
axis([1 500 -5 5])
hold on
plot(conv(x,h2),'g')
axis([1 50 -5 5])
legend('x','conv(x,h1)','conv(x,h2)', 'Location','NorthEastOutside')
print -dpng image.png
</code></pre>
<p>This code saves the produced plot in the current folder directly.</p>
<p>I know this is matlab code and not sage, but the same code produces a larger image (higher resolution) when evaluated directly in matlab, than it does when evaluated in matlab from the sage notebook.</p>
<p>Maybe I am mistaking about this, but these are the "symptoms" I'm experiencing here. </p>
http://ask.sagemath.org/question/8040/scaling-of-png-from-matlab/?comment=21895#post-id-21895I have tried doing this from the command line, and the problem persists. So maybe the problem is caused by the python/sage interface to Matlab.Tue, 05 Apr 2011 07:58:15 -0500http://ask.sagemath.org/question/8040/scaling-of-png-from-matlab/?comment=21895#post-id-21895Comment by kcrisman for <p>Hi</p>
<p>I have been trying find a way to prevent or control scaling of generated png's in the sage notebook.</p>
<p>Sometimes I am using Matlab to generate graphs and it works fine, except that the image is scaled in the sage notebook. If I open the file in the cell folder then I can see that it is scaled, at least when I compare the output from the exact same code evaluated directly in Matlab.</p>
<p>Is there some way to control scaling in sage?</p>
<p>EDIT:
The problem is that the generated image from Matlab has a higher resolution than the image which is saved in the cell folder in the notebook.
It seems as if the image is first saved somewhere else, then scaled, and then saved in the cell folder.
So I am wondering if there is som global setting in sage which sets the scaling factor.
Example:</p>
<pre><code>#auto
%matlab
clear;clc;clf;
h1 = [0.25 0.25 0.25 0.25]; % for n = 0,1,2,3
h2 = [1 -1]; % for n = 0,1
t=0:1:204;
x = randn(1,200);
hfig=figure(1); clf
plot(x)
hold on
plot(conv(x,h1),'r')
axis([1 500 -5 5])
hold on
plot(conv(x,h2),'g')
axis([1 50 -5 5])
legend('x','conv(x,h1)','conv(x,h2)', 'Location','NorthEastOutside')
print -dpng image.png
</code></pre>
<p>This code saves the produced plot in the current folder directly.</p>
<p>I know this is matlab code and not sage, but the same code produces a larger image (higher resolution) when evaluated directly in matlab, than it does when evaluated in matlab from the sage notebook.</p>
<p>Maybe I am mistaking about this, but these are the "symptoms" I'm experiencing here. </p>
http://ask.sagemath.org/question/8040/scaling-of-png-from-matlab/?comment=21919#post-id-21919What happens if you try to run this in the command line? You should be able to use matlab.eval("foo") to try this. That's a way of checking whether the problem is Sage making the plot its own, or the notebook doing something specific to shrink it.Sat, 02 Apr 2011 15:58:41 -0500http://ask.sagemath.org/question/8040/scaling-of-png-from-matlab/?comment=21919#post-id-21919Answer by kcrisman for <p>Hi</p>
<p>I have been trying find a way to prevent or control scaling of generated png's in the sage notebook.</p>
<p>Sometimes I am using Matlab to generate graphs and it works fine, except that the image is scaled in the sage notebook. If I open the file in the cell folder then I can see that it is scaled, at least when I compare the output from the exact same code evaluated directly in Matlab.</p>
<p>Is there some way to control scaling in sage?</p>
<p>EDIT:
The problem is that the generated image from Matlab has a higher resolution than the image which is saved in the cell folder in the notebook.
It seems as if the image is first saved somewhere else, then scaled, and then saved in the cell folder.
So I am wondering if there is som global setting in sage which sets the scaling factor.
Example:</p>
<pre><code>#auto
%matlab
clear;clc;clf;
h1 = [0.25 0.25 0.25 0.25]; % for n = 0,1,2,3
h2 = [1 -1]; % for n = 0,1
t=0:1:204;
x = randn(1,200);
hfig=figure(1); clf
plot(x)
hold on
plot(conv(x,h1),'r')
axis([1 500 -5 5])
hold on
plot(conv(x,h2),'g')
axis([1 50 -5 5])
legend('x','conv(x,h1)','conv(x,h2)', 'Location','NorthEastOutside')
print -dpng image.png
</code></pre>
<p>This code saves the produced plot in the current folder directly.</p>
<p>I know this is matlab code and not sage, but the same code produces a larger image (higher resolution) when evaluated directly in matlab, than it does when evaluated in matlab from the sage notebook.</p>
<p>Maybe I am mistaking about this, but these are the "symptoms" I'm experiencing here. </p>
http://ask.sagemath.org/question/8040/scaling-of-png-from-matlab/?answer=12239#post-id-12239If you could be more explicit in exactly what is/is not being scaled, that could be helpful. Since you are using Matlab graphics, I am not sure how they are being converted to Sage. But maybe this will be helpful.
A Sage-generated graphic can be controlled using the figsize option. Compare the following commands' outputs.
sage: plot(sin(x),(x,-pi,pi),figsize=[2,3])
sage: plot(sin(x),(x,-pi,pi),figsize=[1,6])
sage: plot(sin(x),(x,-pi,pi),aspect_ratio=1)
sage: plot(sin(x),(x,-pi,pi),aspect_ratio=1,figsize=[3,4])
Incidentally, [Ticket 2100](http://trac.sagemath.org/sage_trac/ticket/2100) has some good updates to this. We are just waiting on some final minor review for that.Thu, 31 Mar 2011 03:22:16 -0500http://ask.sagemath.org/question/8040/scaling-of-png-from-matlab/?answer=12239#post-id-12239Answer by Jason Grout for <p>Hi</p>
<p>I have been trying find a way to prevent or control scaling of generated png's in the sage notebook.</p>
<p>Sometimes I am using Matlab to generate graphs and it works fine, except that the image is scaled in the sage notebook. If I open the file in the cell folder then I can see that it is scaled, at least when I compare the output from the exact same code evaluated directly in Matlab.</p>
<p>Is there some way to control scaling in sage?</p>
<p>EDIT:
The problem is that the generated image from Matlab has a higher resolution than the image which is saved in the cell folder in the notebook.
It seems as if the image is first saved somewhere else, then scaled, and then saved in the cell folder.
So I am wondering if there is som global setting in sage which sets the scaling factor.
Example:</p>
<pre><code>#auto
%matlab
clear;clc;clf;
h1 = [0.25 0.25 0.25 0.25]; % for n = 0,1,2,3
h2 = [1 -1]; % for n = 0,1
t=0:1:204;
x = randn(1,200);
hfig=figure(1); clf
plot(x)
hold on
plot(conv(x,h1),'r')
axis([1 500 -5 5])
hold on
plot(conv(x,h2),'g')
axis([1 50 -5 5])
legend('x','conv(x,h1)','conv(x,h2)', 'Location','NorthEastOutside')
print -dpng image.png
</code></pre>
<p>This code saves the produced plot in the current folder directly.</p>
<p>I know this is matlab code and not sage, but the same code produces a larger image (higher resolution) when evaluated directly in matlab, than it does when evaluated in matlab from the sage notebook.</p>
<p>Maybe I am mistaking about this, but these are the "symptoms" I'm experiencing here. </p>
http://ask.sagemath.org/question/8040/scaling-of-png-from-matlab/?answer=12266#post-id-12266If you save the image that is generated in the notebook and then compare the two images, is the one in the notebook actually smaller (i.e., does it have less pixels?) What is the difference in pixel sizes between the two images?
Often a web browser will display an image smaller than it is, but if you right-click on the image and select "View image" or something like that, it will show you the image in the original size.Tue, 05 Apr 2011 16:55:58 -0500http://ask.sagemath.org/question/8040/scaling-of-png-from-matlab/?answer=12266#post-id-12266Comment by Kabi for <p>If you save the image that is generated in the notebook and then compare the two images, is the one in the notebook actually smaller (i.e., does it have less pixels?) What is the difference in pixel sizes between the two images?</p>
<p>Often a web browser will display an image smaller than it is, but if you right-click on the image and select "View image" or something like that, it will show you the image in the original size.</p>
http://ask.sagemath.org/question/8040/scaling-of-png-from-matlab/?comment=21874#post-id-21874I have tried saving the image from the notebook, from the sage interactive console, and directly from matlab. All using the same code. The images from sage are 576x432 and the one directly from matlab is 1200x901.Sun, 10 Apr 2011 11:05:04 -0500http://ask.sagemath.org/question/8040/scaling-of-png-from-matlab/?comment=21874#post-id-21874