Ask Your Question

specify resolution of saved graphic

asked 2011-07-18 18:16:55 +0200

Bill gravatar image

updated 2015-01-13 18:01:25 +0200

FrédéricC gravatar image

I can save a graphic I have created as a svg using the following command:'/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

answered 2011-07-19 06:00:10 +0200

updated 2011-07-19 06:29:24 +0200

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


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()

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

edit flag offensive delete link more


Simon gravatar imageSimon ( 2011-07-19 06:13:43 +0200 )edit

OK. I tried using this command:'/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 18:00:53 +0200 )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 18:02:23 +0200 )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 22:27:12 +0200 )edit

@Simon Thanks for your help!

Bill gravatar imageBill ( 2011-07-20 00:03:16 +0200 )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


Asked: 2011-07-18 18:16:55 +0200

Seen: 2,890 times

Last updated: Jul 19 '11