Ask Your Question
3

specify resolution of saved graphic

asked 2011-07-18 11:16:55 -0500

Bill gravatar image

updated 2015-01-13 11:01:25 -0500

FrédéricC gravatar image

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?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
3

answered 2011-07-18 23:00:10 -0500

updated 2011-07-18 23:29:24 -0500

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.

edit flag offensive delete link more

Comments

http://trac.sagemath.org/sage_trac/ticket/5956

Simon gravatar imageSimon ( 2011-07-18 23:13:43 -0500 )edit

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 gravatar imageBill ( 2011-07-19 11:00:53 -0500 )edit

The image I get is 2850x1919, which at 300dpi is 9.5in x 6.4in, not 12x8. What's going on here?

Bill gravatar imageBill ( 2011-07-19 11:02:23 -0500 )edit

@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 gravatar imageSimon ( 2011-07-19 15:27:12 -0500 )edit

@Simon Thanks for your help!

Bill gravatar imageBill ( 2011-07-19 17:03:16 -0500 )edit

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-07-18 11:16:55 -0500

Seen: 923 times

Last updated: Jul 18 '11