|
270 | 270 | "cell_type": "markdown", |
271 | 271 | "metadata": {}, |
272 | 272 | "source": [ |
273 | | - "To see the image axes in sky coordinates instead of pixel coordinates, a simple option is to use astropy's World Coordinate System (WCS) package, along with matplotlib.pyplot's ``subplot``, ``imshow``, and ``grid`` functions. \n", |
274 | | - "Recall that we imported ``matplotlib.pyplot`` as ``plt`` already, and that we imported the ``astropy.wcs.WCS`` function as simply ``WCS``.\n", |
275 | | - "Find more information about [imshow](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.imshow.html) and [colormaps](https://matplotlib.org/stable/tutorials/colors/colormaps.html) (``cmap``)." |
| 273 | + "To see the image axes in sky coordinates instead of pixel coordinates, a simple option is to use astropy's World Coordinate System (WCS) package, along with matplotlib.pyplot's `subplot`, `imshow`, and `grid` functions. \n", |
| 274 | + "Recall that we imported `matplotlib.pyplot` as `plt` already, and that we imported the `astropy.wcs.WCS` function as simply `WCS`.\n", |
| 275 | + "Find more information about [imshow](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.imshow.html) and [colormaps](https://matplotlib.org/stable/tutorials/colors/colormaps.html) (`cmap`)." |
276 | 276 | ] |
277 | 277 | }, |
278 | 278 | { |
|
282 | 282 | "outputs": [], |
283 | 283 | "source": [ |
284 | 284 | "fig = plt.figure()\n", |
| 285 | + "\n", |
285 | 286 | "# Set the figure's projection to be the WCS of the calexp\n", |
286 | 287 | "plt.subplot(projection=WCS(calexp.getWcs().getFitsMetadata()))\n", |
| 288 | + "\n", |
| 289 | + "# Define the extent in pixel coordinates using the bounding box\n", |
| 290 | + "calexp_extent = (calexp.getBBox().beginX, calexp.getBBox().endX, \n", |
| 291 | + " calexp.getBBox().beginY, calexp.getBBox().endY)\n", |
| 292 | + "\n", |
287 | 293 | "# Display the calexp image data array using the gray colormap (cmap)\n", |
288 | 294 | "# and use approximately the same min and max scale values as above\n", |
289 | | - "im = plt.imshow(calexp.image.array, cmap='gray', vmin=-200.0, vmax=400, origin='lower')\n", |
| 295 | + "im = plt.imshow(calexp.image.array, cmap='gray', vmin=-200.0, vmax=400, \n", |
| 296 | + " extent=calexp_extent, origin='lower')\n", |
| 297 | + "\n", |
290 | 298 | "# Add solid white grid lines\n", |
291 | 299 | "plt.grid(color='white', ls='solid')\n", |
| 300 | + "\n", |
292 | 301 | "# Label axes\n", |
293 | 302 | "plt.xlabel('Right Ascension')\n", |
294 | 303 | "plt.ylabel('Declination')\n", |
295 | 304 | "plt.show()\n", |
| 305 | + "\n", |
296 | 306 | "# Clean up memory\n", |
297 | 307 | "remove_figure(fig)" |
298 | 308 | ] |
|
0 commit comments