Ask Your Question
0

Scaling of png from Matlab

asked 2011-03-31 06:06:22 +0200

Kabi gravatar image

updated 2011-04-05 16:06:59 +0200

kcrisman gravatar image

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.

edit retag flag offensive close merge delete

Comments

What 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.

kcrisman gravatar imagekcrisman ( 2011-04-02 22:58:41 +0200 )edit

I 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.

Kabi gravatar imageKabi ( 2011-04-05 14:58:15 +0200 )edit

Probably right. I've changed the title of the question to address this - hope nobody put in any hard links to the URL!

kcrisman gravatar imagekcrisman ( 2011-04-05 16:07:29 +0200 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2011-04-05 23:55:58 +0200

Jason Grout gravatar image

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?

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.

edit flag offensive delete link more

Comments

I 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.

Kabi gravatar imageKabi ( 2011-04-10 18:05:04 +0200 )edit
0

answered 2011-03-31 10:22:16 +0200

kcrisman gravatar image

If 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 has some good updates to this. We are just waiting on some final minor review for that.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-03-31 06:06:22 +0200

Seen: 779 times

Last updated: Apr 05 '11