def zoomtoimage(fig_hypdata, hypdata_map):
    """
    Try to zoom fig_hypdata (a matpotlib figure handle) to extents of hypdata_map (a raster or similar)
    if hypdata_map is None, use simple autoscale(), which does the work sometimes, especially if image is the only thing in the figure
    """
    if hypdata_map is None:
        fig_hypdata.axes[0].autoscale()
    else:
        maxx = hypdata_map.shape[1]
        maxy = hypdata_map.shape[0]
        fig_hypdata.axes[0].set_xlim((-0.5, maxx - 0.5))
        fig_hypdata.axes[0].set_ylim((maxy - 0.5, -0.5))
        fig_hypdata.canvas.draw()
