LSSTDESC / skyproj

Sky mapping with matplotlib and PROJ
BSD 3-Clause "New" or "Revised" License
11 stars 5 forks source link

Zooming with a colorbar gives an error #65

Open esheldon opened 1 week ago

esheldon commented 1 week ago

Adding a colorbar and then using the zoom feature gives an error

matplotlib 3.8
healsparse 1.10.1
skyproj 1.2.4

Example

import numpy as np
import healsparse
import hpgeom
import matplotlib.pyplot as mplt
import skyproj

def main():
    nside = 256

    area = hpgeom.nside_to_pixel_area(nside=nside)

    radius_degrees = np.sqrt(area) / 2
    print(f'radius {radius_degrees:.3g} degrees')

    ras, decs = 200, 75
    pixelnum = hpgeom.angle_to_pixel(nside, ras, decs)

    ra, dec = hpgeom.pixel_to_angle(nside=nside, pix=pixelnum)

    circ = healsparse.Circle(ra=ra, dec=dec, radius=radius_degrees, value=1)
    smap = circ.get_map(nside_coverage=32, nside_sparse=nside, dtype=np.int16)

    fig, ax = mplt.subplots(figsize=(8, 8))
    sp = skyproj.McBrydeSkyproj(ax=ax)
    im, lon_raster, lat_raster, values_raster = sp.draw_hspmap(
        smap,
        lat_range=[dec-radius_degrees*8, dec+radius_degrees*8],
        lon_range=[ra-radius_degrees*2, ra+radius_degrees*2],
    )
    sp.draw_inset_colorbar()

    mplt.show()

main()
Traceback (most recent call last):
  File "/home/esheldon/miniforge3/envs/test/lib/python3.12/site-packages/matplotlib/cbook.py", line 298, in process
    func(*args, **kwargs)
  File "/home/esheldon/miniforge3/envs/test/lib/python3.12/site-packages/skyproj/_skyproj.py", line 869, in _change_axis
    mappable = ScalarMappable(map_norm, cmap=self._redraw_dict['colorbar'].cmap)
                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'cmap'
esheldon commented 1 week ago

Note this error is reported, but it seems to be caught. So python continues to run after this error is reported.

esheldon commented 1 week ago

The error is gone with 2.0beta