Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird zoom behavior when using with Basemap lib #10

Open
houserockr opened this issue Oct 19, 2024 · 0 comments
Open

Weird zoom behavior when using with Basemap lib #10

houserockr opened this issue Oct 19, 2024 · 0 comments

Comments

@houserockr
Copy link

  • 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant