specify resolution of saved graphic

i like this post (click again to cancel)
2
i dont like this post (click again to cancel)

I can save a graphic I have created as a svg using the following command:

p.save('/home/so10b.svg')

However, my particular graphic is saved as a 39.5MB file, which is too large for my graphic editor to handle well. Saving as .ps creates a 20.4MB file.

In the end, I want a .png, but with particular printed dimensions and resolution. So:

What command will allow me to save a graphic in raster format with specific dimensions and resolution?

asked Jul 18 '11

Bill gravatar image Bill
71 7
i like this answer (click again to cancel)
2
i dont like this answer (click again to cancel) Bill has selected this answer as correct

I think that there are two options for plot() that can also be passed to save(). These are figsize in inches and dpi - the product of which (should) give the resolution of the image (although it doesn't seem to quite come out that way...).

sage: p = plot(sin, (0, 2*pi)); p

sine graph

sage: print p.SHOW_OPTIONS['figsize'], p.SHOW_OPTIONS['dpi']
(6, 3.7082039324993699) 100

sage: p.save(os.path.expanduser('~/sin.default.png'))
sage: p.save(os.path.expanduser('~/sin.20.png'),dpi=20)

sin.default.png comes out at 506*316 pixels and 12.5KB, while sin.20.png is just 101*64 pixels and 1.8KB.


Actually if you look at

sage: print p.matplotlib()
Figure(480x296.656)

This basically matches the size of the outputted png file once you remove the padding.

link

posted Jul 19 '11

Simon gravatar image Simon flag of Australia
265 2 5 18
http://www.physics.uwa.ed...

updated Jul 19 '11

OK. I tried using this command: p.save('/home/bill/demo2.png', xmin=-10, xmax=50, ymin=-10, ymax=30, aspect_ratio=1, axes=False, transparent=True, figsize=(12,8), dpi=300) Bill (Jul 19 '11)
The image I get is 2850x1919, which at 300dpi is 9.5in x 6.4in, not 12x8. What's going on here? Bill (Jul 19 '11)
@Bill: Yeah, as I said - it doesn't quite work the way it should... I'm not sure why. I'm not an expert on sage graphics nor matplotlib, so it might take a lot of digging in the code to track down what's going on. Simon (Jul 19 '11)
@Simon Thanks for your help! Bill (Jul 19 '11)
see 1 more comment

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
[hide preview]

Question tools

Tags:

Stats:

Asked: Jul 18 '11

Seen: 227 times

Last updated: Jul 19 '11

powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.