Google Groups

Re: {SunPy} Creating a simple plot in SunPy and saving at an image's native resolution

Richard Schwartz Jan 20, 2012 11:19 AM
Posted in group: SunPy
I think I just updated by Sunpy
cd C:\sunpy\
"%ProgramFiles(x86)%\Git\bin\git" pull

Good things appeared to happen
Then I opened Spyder using Python(x,y) to try Keith's second code block and it didn't like it.  Anyone care to tell me what has happened?  I use Windows 7.

Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.

>>> import sunpy
>>> import matplotlib.pyplot as plt
>>> aia = sunpy.make_map(sunpy.AIA_171_IMAGE)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "c:\sunpy\sunpy\map\", line 58, in make_map
  File "c:\sunpy\sunpy\map\", line 238, in read
    header, data = cls.parse_file(filepath)
  File "c:\sunpy\sunpy\map\", line 211, in parse_file
    from import read_file
  File "c:\sunpy\sunpy\io\", line 3, in <module>
    from import fits, jp2
  File "c:\sunpy\sunpy\io\", line 27, in <module>
    import pyfits
  File "C:\Python27\lib\site-packages\pyfits-2.4.0-py2.7-win32.egg\pyfits\", line 17, in <module>
    from core import *
  File "C:\Python27\lib\site-packages\pyfits-2.4.0-py2.7-win32.egg\pyfits\", line 34, in <module>
    import gzip
  File "C:\Python27\lib\", line 36, in <module>
    class GzipFile(io.BufferedIOBase):
AttributeError: 'module' object has no attribute 'BufferedIOBase'

On 1/20/2012 9:21 AM, Keith Hughitt wrote:
The plot() and show() methods of SunPy Map objects currently include axes labels, a title and color bar.

Further, saving such a plot will result in an image with a different number of pixels than the image that was used to make the Map, e.g.:

import sunpy
plot = sunpy.make_map(sunpy.AIA_171_IMAGE).plot()

Plotting an image in Matplotlib and saving it at it's natural scale without any extra labels or padding turns out to be a bit akward:

import sunpy
import matplotlib.pyplot as plt

aia = sunpy.make_map(sunpy.AIA_171_IMAGE)

fig = plt.figure(frameon=False)
fig.set_size_inches(10.24, 10.24)
ax = plt.Axes(fig, [0., 0., 1., 1.])

ax.imshow(aia, aspect='normal', norm=aia.norm(), cmap=aia.cmap)
fig.savefig('test.png', dpi=100)

Compare this with saving an (unscaled/grayscale) image with PIL:

import sunpy
import Image

aia = sunpy.make_map(sunpy.AIA_171_IMAGE)
im = Image.fromarray(aia)

I'm thinking about adding a method to the BaseMap to help make it easier to achieve the above effect. One approach would be to
create a method like "save_image" to achieve the above effect. I wonder if we should also take a closer look at .plot() though
and consider making it possible to toggle on/off things like title, colorbar, and axes labels?

You received this message because you are subscribed to the Google Groups "SunPy" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at