@@ -57,10 +57,10 @@ class CompositeMap:
5757 Examples
5858 --------
5959 >>> import sunpy
60- >>> sunpy.CompositeMap(sunpy.AIA_171_IMAGE, sunpy.RHESSI_IMAGE).show ()
60+ >>> sunpy.CompositeMap(sunpy.AIA_171_IMAGE, sunpy.RHESSI_IMAGE).peek ()
6161 >>> comp_map = sunpy.CompositeMap(sunpy.AIA_171_IMAGE, sunpy.EIT_195_IMAGE)
6262 >>> comp_map.add_map(sunpy.RHESSI_IMAGE)
63- >>> comp_map.show ()
63+ >>> comp_map.peek ()
6464
6565 """
6666 def __init__ (self , * args ):
@@ -122,6 +122,10 @@ def remove_map(self, index):
122122 def list_maps (self ):
123123 """Prints a list of the currently included maps"""
124124 print [m .__class__ for m in self ._maps ]
125+
126+ def get_map (self , index ):
127+ """ Returns the map with given index """
128+ return self ._maps [index ]
125129
126130 def get_alpha (self , index = None ):
127131 """Gets the alpha-channel value for a layer in the composite image"""
@@ -192,48 +196,57 @@ def set_zorder(self, index, zorder):
192196 """
193197 self ._maps [index ].zorder = zorder
194198
195- def plot (self , axes = None , gamma = 1.0 , # pylint: disable=W0613
196- basic_plot = False , annotate = True , # pylint: disable=W0613
199+ def plot (self , axes = None , gamma = None , annotate = True , # pylint: disable=W0613
197200 title = "SunPy Composite Plot" , ** matplot_args ):
198201 """Plots the composite map object using matplotlib
199202
200203 Parameters
201204 ----------
202- title : string
203- Title to use for the plot
204- overlays : list
205- List of overlays to include in the plot
205+ axes: matplotlib.axes object or None
206+ If provided the image will be plotted on the given axes. Else the
207+ current matplotlib axes will be used.
208+
209+ gamma : float
210+ Gamma value to use for the color map
211+
212+ annotate : bool
213+ If true, the data is plotted at it's natural scale; with
214+ title and axis labels.
215+
206216 **matplot_args : dict
207217 Matplotlib Any additional imshow arguments that should be used
208218 when plotting the image.
209219
210220 Returns
211221 -------
212- out : matplotlib.figure.Figure
213- A Matplotlib figure instance representing the composite map plot
222+ ret : List
223+ List of axes image or quad contour sets that have been plotted.
214224 """
215225
216226 #Get current axes
217227 if not axes :
218228 axes = plt .gca ()
219229
220- # x-axis label
221- if self ._maps [0 ].coordinate_system ['x' ] == 'HG' :
222- xlabel = 'Longitude [%s]' % self ._maps [0 ].units ['x' ]
223- else :
224- xlabel = 'X-position [%s]' % self ._maps [0 ].units ['x' ]
225-
226- # y-axis label
227- if self ._maps [0 ].coordinate_system ['y' ] == 'HG' :
228- ylabel = 'Latitude [%s]' % self ._maps [0 ].units ['y' ]
229- else :
230- ylabel = 'Y-position [%s]' % self ._maps [0 ].units ['y' ]
231-
232- axes .set_xlabel (xlabel )
233- axes .set_ylabel (ylabel )
234-
235- axes .set_title (title )
230+ if annotate :
231+ # x-axis label
232+ if self ._maps [0 ].coordinate_system ['x' ] == 'HG' :
233+ xlabel = 'Longitude [%s]' % self ._maps [0 ].units ['x' ]
234+ else :
235+ xlabel = 'X-position [%s]' % self ._maps [0 ].units ['x' ]
236+
237+ # y-axis label
238+ if self ._maps [0 ].coordinate_system ['y' ] == 'HG' :
239+ ylabel = 'Latitude [%s]' % self ._maps [0 ].units ['y' ]
240+ else :
241+ ylabel = 'Y-position [%s]' % self ._maps [0 ].units ['y' ]
242+
243+ axes .set_xlabel (xlabel )
244+ axes .set_ylabel (ylabel )
245+
246+ axes .set_title (title )
236247
248+ #Define a list of plotted objects
249+ ret = []
237250 # Plot layers of composite map
238251 for m in self ._maps :
239252 # Parameters for plotting
@@ -248,39 +261,40 @@ def plot(self, axes=None, gamma=1.0, # pylint: disable=W0613
248261 params .update (matplot_args )
249262
250263 if m .levels is False :
251- ret = axes .imshow (m , ** params )
264+ ret . append ( axes .imshow (m , ** params ) )
252265
253266 # Use contour for contour data, and imshow otherwise
254267 if m .levels is not False :
255268 # Set data with values <= 0 to transparent
256269 # contour_data = np.ma.masked_array(m, mask=(m <= 0))
257- ret = axes .contour (m , m .levels , ** params )
270+ ret .append (axes .contour (m , m .levels , ** params ))
271+ #Set the label of the first line so a legend can be created
272+ ret [- 1 ].collections [0 ].set_label (m .name )
258273
259274 # Adjust axes extents to include all data
260275 axes .axis ('image' )
261276
262277 #Set current image (makes colorbar work)
263- plt .sci (ret )
278+ plt .sci (ret [ 0 ] )
264279 return ret
265280
266- def peek (self , gamma = None ,
267- colorbar = True , basic_plot = False , ** matplot_args ):
281+ def peek (self , gamma = None , colorbar = True , basic_plot = False ,
282+ ** matplot_args ):
268283 """Displays the map in a new figure
269284
270285 Parameters
271286 ----------
272- draw_limb : bool
273- Whether the solar limb should be plotted.
274- draw_grid : bool or number
275- Whether solar meridians and parallels are plotted. If float then sets
276- degree difference between parallels and meridians.
277287 gamma : float
278288 Gamma value to use for the color map
279- colorbar : bool
280- Whether to display a colorbar next to the plot
289+
290+ colorbar : bool or int
291+ Whether to display a colorbar next to the plot.
292+ If specified as an integer a colorbar is plotted for that index.
293+
281294 basic_plot : bool
282295 If true, the data is plotted by itself at it's natural scale; no
283296 title, labels, or axes are shown.
297+
284298 **matplot_args : dict
285299 Matplotlib Any additional imshow arguments that should be used
286300 when plotting the image.
@@ -298,8 +312,12 @@ def peek(self, gamma=None,
298312 else :
299313 axes = figure .add_subplot (111 )
300314
301- self .plot (axes = axes ,** matplot_args )
315+ ret = self .plot (axes = axes ,** matplot_args )
302316
317+ if not isinstance (colorbar , bool ) and isinstance (colorbar , int ):
318+ figure .colorbar (ret [colorbar ])
319+ elif colorbar :
320+ plt .colorbar ()
303321 #if draw_limb:
304322 # self.draw_limb(axes=axes)
305323
@@ -311,7 +329,7 @@ def peek(self, gamma=None,
311329 #else:
312330 # raise TypeError("draw_grid should be bool, int, long or float")
313331
314- plt .show ()
332+ figure .show ()
315333
316334 return figure
317335
0 commit comments