问题
I am using the following code to plot the Matplotlib Basemap on tkinter canvas:
from tkinter import *
from tkinter.ttk import *
import numpy as np
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import (NavigationToolbar2Tk)
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg as FigureCanvas
import os
os.environ['PROJ_LIB'] = r'C:\Users\AppData\Local\Continuum\anaconda3\pkgs\proj4-4.9.3-vc14_5\Library\share'
from mpl_toolkits.basemap import Basemap
w=Tk()
fig_plot = plt.Figure(figsize=(7.5,4), dpi = 100)
ax = fig_plot.add_subplot(111)
m = Basemap(projection='cyl',
llcrnrlon = -180, llcrnrlat = -90,
urcrnrlon = 180, urcrnrlat = 90,
resolution='l', ax = ax)
m.drawmapboundary(fill_color='aqua')
m.fillcontinents(color='#ddaa66',lake_color='aqua')
m.drawcoastlines()
m.drawparallels(range(-90, 90, 30), labels = [False, True, True, False])
m.drawmeridians(range(-180, 180, 30), labels = [True, False, False, True])
Canvas = FigureCanvas(fig_plot, w)
ax.set_aspect('auto')
fig_plot.subplots_adjust(left=0.0, bottom=0.0, right=1.0, top=1.0)
Canvas.draw()
Canvas.get_tk_widget().pack(side='bottom', fill='both', padx=100, pady=10, expand = 1)
toolbar = NavigationToolbar2Tk(Canvas, w)
toolbar.update()
Canvas._tkcanvas.pack(side='bottom', fill='both', padx=10, pady=10, expand = 1)
w.mainloop()
After running the above code the Basemap successfully gets plotted on the entire tkinter canvas area as shown in the figure below:
Now the issue which I am facing is that after I tried to zoom in to particular region of the map, then the image is getting stretched as shown in figure below::
Can someone help me out as to how I can avoid this image stretching while using zoom to rectangle option in matplotlib.
来源:https://stackoverflow.com/questions/62966650/matplotlib-image-getting-stretched-after-using-zoom-to-rectangle