def updatefig(i, im, annotate, ani_data, removes): while removes: removes.pop(0).remove() im.set_array(ani_data[i].data) im.set_cmap(ani_data[i].plot_settings['cmap']) norm = deepcopy(ani_data[i].plot_settings['norm']) # The following explicit call is for bugged versions of Astropy's # ImageNormalize norm.autoscale_None(ani_data[i].data) im.set_norm(norm) if wcsaxes_compat.is_wcsaxes(axes): im.axes.reset_wcs(ani_data[i].wcs) wcsaxes_compat.default_wcs_grid(axes) else: bl = ani_data[i]._get_lon_lat(ani_data[i].bottom_left_coord) tr = ani_data[i]._get_lon_lat(ani_data[i].top_right_coord) x_range = list( u.Quantity([bl[0], tr[0]]).to(ani_data[i].spatial_units[0]).value) y_range = list( u.Quantity([bl[1], tr[1]]).to(ani_data[i].spatial_units[1]).value) im.set_extent(np.concatenate((x_range.value, y_range.value))) if annotate: annotate_frame(i) removes += list(plot_function(fig, axes, ani_data[i]))
def updatefig(self, val, im, slider): # Remove all the objects that need to be removed from the # plot while self.remove_obj: self.remove_obj.pop(0).remove() i = int(val) im.set_array(self.data[i].data) im.set_cmap(self.mapcube[i].plot_settings['cmap']) norm = deepcopy(self.mapcube[i].plot_settings['norm']) # The following explicit call is for bugged versions of Astropy's ImageNormalize norm.autoscale_None(self.data[i].data) im.set_norm(norm) if wcsaxes_compat.is_wcsaxes(im.axes): im.axes.reset_wcs(self.mapcube[i].wcs) wcsaxes_compat.default_wcs_grid(im.axes) # Having this line in means the plot will resize for non-homogenous # maps. However it also means that if you zoom in on the plot bad # things happen. # im.set_extent(self.mapcube[i].xrange + self.mapcube[i].yrange) if self.annotate: self._annotate_plot(i) self.remove_obj += list(self.user_plot_function(self.fig, self.axes, self.mapcube[i]))
def _drawFallback(self, model): self.figure.clear() try: s_map = model.map plot_preferences = model.plot_preferences ax = self.figure.add_subplot(111, projection=s_map) image = ax.imshow(model.data, cmap=model.cmap, norm=model.norm, interpolation=model.interpolation, origin=model.origin) if plot_preferences["show_colorbar"]: self.figure.colorbar(image) if plot_preferences["show_limb"]: s_map.draw_limb(axes=ax) if plot_preferences["contours"]: levels = sorted(plot_preferences["contours"]) s_map.draw_contours(levels * u.percent, axes=ax) if plot_preferences["draw_grid"]: s_map.draw_grid(grid_spacing=10 * u.deg, axes=ax) if plot_preferences["wcs_grid"] and wcsaxes_compat.is_wcsaxes(ax): wcsaxes_compat.default_wcs_grid(ax, units=s_map.spatial_units, ctypes=s_map.wcs.wcs.ctype) except Exception as ex: self.figure.clear() self.figure.text(0.5, 0.5, s="Error during rendering data: " + str(ex), ha="center", va="center")
def updatefig(i, im, annotate, ani_data, removes): while removes: removes.pop(0).remove() im.set_array(ani_data[i].data) im.set_cmap(ani_data[i].plot_settings['cmap']) norm = deepcopy(ani_data[i].plot_settings['norm']) # The following explicit call is for bugged versions of Astropy's # ImageNormalize norm.autoscale_None(ani_data[i].data) im.set_norm(norm) if wcsaxes_compat.is_wcsaxes(axes): im.axes.reset_wcs(ani_data[i].wcs) wcsaxes_compat.default_wcs_grid(axes) else: bl = ani_data[i]._get_lon_lat(ani_data[i].bottom_left_coord) tr = ani_data[i]._get_lon_lat(ani_data[i].top_right_coord) x_range = list(u.Quantity([bl[0], tr[0]]).to(ani_data[i].spatial_units[0]).value) y_range = list(u.Quantity([bl[1], tr[1]]).to(ani_data[i].spatial_units[1]).value) im.set_extent(np.concatenate((x_range.value, y_range.value))) if annotate: annotate_frame(i) removes += list(plot_function(fig, axes, ani_data[i]))
def updatefig(self, val, im, slider): # Remove all the objects that need to be removed from the # plot while self.remove_obj: self.remove_obj.pop(0).remove() i = int(val) im.set_array(self.data[i].data) im.set_cmap(self.mapcube[i].plot_settings['cmap']) norm = deepcopy(self.mapcube[i].plot_settings['norm']) # The following explicit call is for bugged versions of Astropy's ImageNormalize norm.autoscale_None(self.data[i].data) im.set_norm(norm) if wcsaxes_compat.is_wcsaxes(im.axes): im.axes.reset_wcs(self.mapcube[i].wcs) wcsaxes_compat.default_wcs_grid(im.axes) # Having this line in means the plot will resize for non-homogenous # maps. However it also means that if you zoom in on the plot bad # things happen. # im.set_extent(self.mapcube[i].xrange + self.mapcube[i].yrange) if self.annotate: self._annotate_plot(i) self.remove_obj += list( self.user_plot_function(self.fig, self.axes, self.mapcube[i]))
def updatefig(i, im, annotate, ani_data, removes): while removes: removes.pop(0).remove() im.set_array(ani_data[i].data) im.set_cmap(ani_data[i].plot_settings['cmap']) norm = deepcopy(ani_data[i].plot_settings['norm']) # The following explicit call is for bugged versions of Astropy's # ImageNormalize norm.autoscale_None(ani_data[i].data) im.set_norm(norm) if wcsaxes_compat.is_wcsaxes(axes): im.axes.reset_wcs(ani_data[i].wcs) wcsaxes_compat.default_wcs_grid(axes, ani_data[i].spatial_units, ani_data[i].coordinate_system) else: im.set_extent( np.concatenate( (ani_data[i].xrange.value, ani_data[i].yrange.value))) if annotate: annotate_frame(i) removes += list(plot_function(fig, axes, ani_data[i]))
def updatefig(i, im, annotate, ani_data, removes): while removes: removes.pop(0).remove() im.set_array(ani_data[i].data) im.set_cmap(self.maps[i].plot_settings['cmap']) norm = deepcopy(self.maps[i].plot_settings['norm']) # The following explicit call is for bugged versions of Astropy's ImageNormalize norm.autoscale_None(ani_data[i].data) im.set_norm(norm) if wcsaxes_compat.is_wcsaxes(axes): im.axes.reset_wcs(self.maps[i].wcs) wcsaxes_compat.default_wcs_grid(axes) else: im.set_extent(np.concatenate((self.maps[i].xrange.value, self.maps[i].yrange.value))) if annotate: annotate_frame(i) removes += list(plot_function(fig, axes, self.maps[i]))
def updatefig(self, val, im, slider): """ ? Parameters ---------- val : ? ? im : ? ? Returns ------- .. todo:: improve documentation """ # Remove all the objects that need to be removed from the # plot while self.remove_obj: self.remove_obj.pop(0).remove() i = int(val) im.set_array(self.data[i].data) im.set_cmap(self.mapcube[i].plot_settings['cmap']) im.set_norm(self.mapcube[i].plot_settings['norm']) if wcsaxes_compat.is_wcsaxes(im.axes): im.axes.reset_wcs(self.mapcube[i].wcs) wcsaxes_compat.default_wcs_grid(im.axes) # Having this line in means the plot will resize for non-homogenous # maps. However it also means that if you zoom in on the plot bad # things happen. # im.set_extent(self.mapcube[i].xrange + self.mapcube[i].yrange) if self.annotate: self._annotate_plot(i) self.remove_obj += list(self.user_plot_function(self.fig, self.axes, self.mapcube[i]))
def plot(self, gamma=None, annotate=True, axes=None, **imshow_args): """ Plots the map object using matplotlib, in a method equivalent to plt.imshow() using nearest neighbour interpolation. Parameters ---------- gamma : float Gamma value to use for the color map annotate : bool If true, the data is plotted at it's natural scale; with title and axis labels. axes: matplotlib.axes object or None If provided the image will be plotted on the given axes. Else the current matplotlib axes will be used. **imshow_args : dict Any additional imshow arguments that should be used when plotting the image. Examples -------- #Simple Plot with color bar >>> aiamap.plot() >>> plt.colorbar() #Add a limb line and grid >>> aia.plot() >>> aia.draw_limb() >>> aia.draw_grid() """ #Get current axes if not axes: axes = wcsaxes_compat.gca_wcs(self.wcs) # Check that the image is properly oriented if (not wcsaxes_compat.is_wcsaxes(axes) and not np.array_equal(self.rotation_matrix, np.matrix(np.identity(2)))): warnings.warn("This map is not properly oriented. Plot axes may be incorrect", Warning) # Normal plot if annotate: axes.set_title("{name} {date:{tmf}}".format(name=self.name, date=parse_time(self.date), tmf=TIME_FORMAT)) # x-axis label if self.coordinate_system.x == 'HG': xlabel = 'Longitude [{lon}]'.format(lon=self.units.x) else: xlabel = 'X-position [{xpos}]'.format(xpos=self.units.x) # y-axis label if self.coordinate_system.y == 'HG': ylabel = 'Latitude [{lat}]'.format(lat=self.units.y) else: ylabel = 'Y-position [{ypos}]'.format(ypos=self.units.y) axes.set_xlabel(xlabel) axes.set_ylabel(ylabel) cmap = deepcopy(self.cmap) if gamma is not None: cmap.set_gamma(gamma) kwargs = self._mpl_imshow_kwargs(axes, cmap) kwargs.update(imshow_args) if self.mask is None: ret = axes.imshow(self.data, **kwargs) else: ret = axes.imshow(np.ma.array(np.asarray(self.data), mask=self.mask), **kwargs) if wcsaxes_compat.is_wcsaxes(axes): wcsaxes_compat.default_wcs_grid(axes) #Set current image (makes colorbar work) plt.sca(axes) plt.sci(ret) return ret
def plot(self, annotate=True, axes=None, title=True, **imshow_kwargs): """ Plots the map object using matplotlib, in a method equivalent to plt.imshow() using nearest neighbour interpolation. Parameters ---------- annotate : bool If True, the data is plotted at it's natural scale; with title and axis labels. axes: `~matplotlib.axes` or None If provided the image will be plotted on the given axes. Else the current matplotlib axes will be used. **imshow_kwargs : dict Any additional imshow arguments that should be used when plotting. Examples -------- #Simple Plot with color bar >>> aiamap.plot() # doctest: +SKIP >>> plt.colorbar() # doctest: +SKIP #Add a limb line and grid >>> aia.plot() # doctest: +SKIP >>> aia.draw_limb() # doctest: +SKIP >>> aia.draw_grid() # doctest: +SKIP """ # Get current axes if not axes: axes = wcsaxes_compat.gca_wcs(self.wcs) # Check that the image is properly oriented if not wcsaxes_compat.is_wcsaxes(axes) and not np.array_equal(self.rotation_matrix, np.matrix(np.identity(2))): warnings.warn("This map is not properly oriented. Plot axes may be incorrect", Warning) # Normal plot imshow_args = deepcopy(self.plot_settings) if imshow_args.has_key("title"): plot_settings_title = imshow_args.pop("title") else: plot_settings_title = self.name if annotate: if title is True: title = plot_settings_title if title: axes.set_title(title) # x-axis label if self.coordinate_system.x == "HG": xlabel = "Longitude [{lon}]".format(lon=self.units.x) else: xlabel = "X-position [{xpos}]".format(xpos=self.units.x) # y-axis label if self.coordinate_system.y == "HG": ylabel = "Latitude [{lat}]".format(lat=self.units.y) else: ylabel = "Y-position [{ypos}]".format(ypos=self.units.y) axes.set_xlabel(xlabel) axes.set_ylabel(ylabel) if not wcsaxes_compat.is_wcsaxes(axes): imshow_args.update({"extent": list(self.xrange.value) + list(self.yrange.value)}) imshow_args.update(imshow_kwargs) if self.mask is None: ret = axes.imshow(self.data, **imshow_args) else: ret = axes.imshow(np.ma.array(np.asarray(self.data), mask=self.mask), **imshow_args) if wcsaxes_compat.is_wcsaxes(axes): wcsaxes_compat.default_wcs_grid(axes) # Set current image (makes colorbar work) plt.sca(axes) plt.sci(ret) return ret