Skip to content

Weird zoom behavior when using with Basemap lib #10

Open
@houserockr

Description

@houserockr
  • mpl-pan-zoom version: 1.0.0
  • Python version: 3.11.4
  • Operating System: MacOS 15.0.1

Description

When using this package in conjunction with the Basemap library from https://matplotlib.org/basemap/stable/ zooming by scrolling seems to scale different elements of a plot/map differently and then elements of the plot "drift" apart from each other.

What I Did

#!/usr/bin/env python3

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
from mpl_pan_zoom import PanManager, zoom_factory, MouseButton

def plot_arrow(xs, ys):
    plt.arrow(xs[0], ys[0], xs[1]-xs[0], ys[1]-ys[0],
              shape='full', color='k', fill=True, length_includes_head=True,
               width=2000, overhang=0.5)

def main():
    fig, ax = plt.subplots(constrained_layout=True)
    disconnect_zoom = zoom_factory(ax)
    pan_manager = PanManager(fig, MouseButton.MIDDLE)

    m = Basemap(projection='stere', lat_0=51.0, lon_0=10.0, width=750000, height=900000,
                resolution ='i',area_thresh=1000.)
    
    lat = np.array([49.555396, 52.537839])
    lon = np.array([7.960521,  12.797734])
    m.plot(lon,lat, color='k', lw=1, latlon=True)

    # draw coastlines, meridians and parallels.
    m.drawcoastlines()
    m.drawcountries()
    m.drawmapboundary(fill_color='#99ffff')
    m.fillcontinents(color='#cc9966',lake_color='#99ffff')
    m.drawparallels(np.arange(47,55,1),labels=[1,1,0,0])
    m.drawmeridians(np.arange(5,15,1),labels=[0,0,0,1])

    plt.show()

if __name__ == "__main__":
    main()

After starting the script:
mpl-map_pre

After scrolling/zooming with the mouse wheel:
mpl-map_post

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions