Repository: sunpy/sunpy

Issue:
Add label to colorbar in map.peek()
It would be nice to set the colorbar label from the unit of the map data (from the BUNIT FITS keyword), currently it is missing:

![Screenshot 2021-01-25 at 14 40 05](https://user-images.githubusercontent.com/6197628/105720567-78c71200-5f1b-11eb-8927-cd047d1e04be.png)



Discussion:
@dstansby I would like to work on this. Please assign this to me. I'm, however ,new to open source ,so any help/guidance is more then welcome. I will start with going through the Developers guide and Newcomers guide for now.
Thanks
Death to `.peek()`!  Long live `.quicklook()`! =P

(Of course, `.quicklook()` doesn't have this feature either...)
> @dstansby I would like to work on this. Please assign this to me. I'm, however ,new to open source ,so any help/guidance is more then welcome. I will start with going through the Developers guide and Newcomers guide for now.
> Thanks

We tend to not use the "assignee" part of GitHub issues, our issues are generally low traffic enough to not cause a problem with not using this feature of GitHub.

The newcomers guide is the best place to start, if you hit any roadblocks, you should join the matrix channel and we debug it there.
@nabobalis Thanks! I will do that.
How should the label for the colorbar look like, I'm a tad bit confused.
For the label text, it should just take the unit from the `.unit` attribute, ie. `str(self.unit)` - does that clear up the confusion?
> For the label text, it should just take the unit from the `.unit` attribute, ie. `str(self.unit)` - does that clear up the confusion?

Yep, thanks I shall make a PR regarding this soon.

Resolving patch:
diff --git a/sunpy/map/mapbase.py b/sunpy/map/mapbase.py
--- a/sunpy/map/mapbase.py
+++ b/sunpy/map/mapbase.py
@@ -2052,7 +2052,9 @@ def peek(self, draw_limb=False, draw_grid=False,
                 pad = 0.12  # Pad to compensate for ticks and axes labels
             else:
                 pad = 0.05  # Default value for vertical colorbar
-            figure.colorbar(im, pad=pad)
+            colorbar_label = str(self.unit) if self.unit is not None else ""
+            figure.colorbar(im, pad=pad).set_label(colorbar_label,
+                                                   rotation=0, labelpad=-50, y=-0.02, size=12)
 
         if draw_limb:
             self.draw_limb(axes=axes)


Test patch:
diff --git a/sunpy/tests/figure_hashes_mpl_332_ft_261_astropy_403.json b/sunpy/tests/figure_hashes_mpl_332_ft_261_astropy_403.json
--- a/sunpy/tests/figure_hashes_mpl_332_ft_261_astropy_403.json
+++ b/sunpy/tests/figure_hashes_mpl_332_ft_261_astropy_403.json
@@ -6,12 +6,12 @@
   "sunpy.map.tests.test_plotting.test_plot_aia171": "1e5435af7bb854d47ebeabf354350f27bf989325aa5d77b930bdcdb043ce25df",
   "sunpy.map.tests.test_plotting.test_plot_rotated_aia171": "06ed44d872a6e1e5ec2dd6a522ee81f68a2c8420dea1bc7491bc64d9e3d3e147",
   "sunpy.map.tests.test_plotting.test_plot_aia171_clip": "241cb73a89ca5d80b9eb673e6e0fda97b842b38be3ea3f25c06e2f8aeb6a4dfc",
-  "sunpy.map.tests.test_plotting.test_peek_aia171": "bbff0c076e8e21d6d888898d2952183cadc25fdbd81fce808602ed51aab1cbbe",
-  "sunpy.map.tests.test_plotting.test_peek_grid_aia171": "711b826471e6a7e65c56fe49bb203ebcdbc084a31b94146ebec1cada65e04806",
-  "sunpy.map.tests.test_plotting.test_peek_grid_spacing_aia171": "23d3c95df35606cef4dc9392796412412ba06382f21203fc9b28754b713889ea",
-  "sunpy.map.tests.test_plotting.test_peek_limb_aia171": "9d083f30fda1aed9436e7b81b3d689d97a39db0cb2fc13e382a93dfe20be518b",
+  "sunpy.map.tests.test_plotting.test_peek_aia171": "66b8e96ed6c074e87ff328a9154f4dbd32c11cb9d3f83f692c47ddd2946eefe1",
+  "sunpy.map.tests.test_plotting.test_peek_grid_aia171": "1aa43c4ea9f3f16b0680e7679a81b5a25fb8f40d2cc2f212f0268599f349be55",
+  "sunpy.map.tests.test_plotting.test_peek_grid_spacing_aia171": "852dfebc9713bfc5ad991d27505b90df58bbb91f45bfc0bc0128d41a531681e8",
+  "sunpy.map.tests.test_plotting.test_peek_limb_aia171": "450dde954bab41a0a20f7895364a24622117925638468e8eb1db3ebee0ab370e",
   "sunpy.map.tests.test_plotting.test_draw_grid_aia171": "5d7221e2d43aefffc4ef30b020fb7207b8d7f42dc5fd97dea25a6d351b7c5cc7",
-  "sunpy.map.tests.test_plotting.test_peek_grid_limb_aia171": "65de3e3b99ddeea2a27ebc6c65cd2d2296e08d2f0ed188599a469728b002fd2b",
+  "sunpy.map.tests.test_plotting.test_peek_grid_limb_aia171": "7dd97105cd9590374e4bbfcfa4f5c37666f9640e32db7086ce97e31c63e1966d",
   "sunpy.map.tests.test_plotting.test_plot_aia171_nowcsaxes": "6e9cdda3aa9ed603f4be536634543ce8c1a6718b79aed57f850a187f8150446e",
   "sunpy.map.tests.test_plotting.test_rectangle_aia171_width_height": "455246d338564add5be94c1dc0ff5740a90d21d8ef7da9f392ba3a01237ef5b8",
   "sunpy.map.tests.test_plotting.test_rectangle_aia171_top_right": "455246d338564add5be94c1dc0ff5740a90d21d8ef7da9f392ba3a01237ef5b8",
diff --git a/sunpy/tests/figure_hashes_mpl_dev_ft_261_astropy_dev.json b/sunpy/tests/figure_hashes_mpl_dev_ft_261_astropy_dev.json
--- a/sunpy/tests/figure_hashes_mpl_dev_ft_261_astropy_dev.json
+++ b/sunpy/tests/figure_hashes_mpl_dev_ft_261_astropy_dev.json
@@ -6,12 +6,12 @@
   "sunpy.map.tests.test_plotting.test_plot_aia171": "1e5435af7bb854d47ebeabf354350f27bf989325aa5d77b930bdcdb043ce25df",
   "sunpy.map.tests.test_plotting.test_plot_rotated_aia171": "d07b653c762bf20478ea33e9712e4eacd7bd0a0fc8dbe16964e8b4374f40120d",
   "sunpy.map.tests.test_plotting.test_plot_aia171_clip": "241cb73a89ca5d80b9eb673e6e0fda97b842b38be3ea3f25c06e2f8aeb6a4dfc",
-  "sunpy.map.tests.test_plotting.test_peek_aia171": "c19f20b06e6a2fb721f7d3fc9fd60653fdc73454bcd8dbbc0637ba29187008b8",
-  "sunpy.map.tests.test_plotting.test_peek_grid_aia171": "303f622c0c15cf5613a15c6dccb52953a52f3acb52a42f5e11c8a64a4b493086",
-  "sunpy.map.tests.test_plotting.test_peek_grid_spacing_aia171": "349b964410d2935abb65f8cf98ba7450fe7da53c50f2c632b5b080efc93d36f0",
-  "sunpy.map.tests.test_plotting.test_peek_limb_aia171": "a9c991bcc89fb2901437cd72f6b5bf82a3f7c2b5d5486c81acb217b1ba95f1e4",
+  "sunpy.map.tests.test_plotting.test_peek_aia171": "dbe7898896e7d6f3d6c4b26eaaea0e1dea6c1e6b7129c1440a8dd1f6eb66c683",
+  "sunpy.map.tests.test_plotting.test_peek_grid_aia171": "8c67dcc1e46eb0f80350efb3c8c1619c12ec42b118694279dd694f1ce8b18589",
+  "sunpy.map.tests.test_plotting.test_peek_grid_spacing_aia171": "a924028bc933a08056dff5945531932e146efe20bae658bf5788404f74692cf4",
+  "sunpy.map.tests.test_plotting.test_peek_limb_aia171": "d971d6d3944594917189c3e00064c9a2073f8a27c8376a5b8ec5d0fe410d4dbb",
   "sunpy.map.tests.test_plotting.test_draw_grid_aia171": "5d7221e2d43aefffc4ef30b020fb7207b8d7f42dc5fd97dea25a6d351b7c5cc7",
-  "sunpy.map.tests.test_plotting.test_peek_grid_limb_aia171": "58247a0ca97e3a453bd3a78d15feb391767de6c7fd7e4940bd081db1b0f4faaa",
+  "sunpy.map.tests.test_plotting.test_peek_grid_limb_aia171": "2ab774779b25e7f6d1d20cefa84aa8872857089c83931512d384c3f541f9a1dd",
   "sunpy.map.tests.test_plotting.test_plot_aia171_nowcsaxes": "6e9cdda3aa9ed603f4be536634543ce8c1a6718b79aed57f850a187f8150446e",
   "sunpy.map.tests.test_plotting.test_rectangle_aia171_width_height": "455246d338564add5be94c1dc0ff5740a90d21d8ef7da9f392ba3a01237ef5b8",
   "sunpy.map.tests.test_plotting.test_rectangle_aia171_top_right": "455246d338564add5be94c1dc0ff5740a90d21d8ef7da9f392ba3a01237ef5b8",