【发布时间】:2023-02-19 21:05:58
【问题描述】:
所以我从我的老师那里得到了这段旧代码,它使用底图绘制了一个 Mollweide 投影
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
from itertools import chain
def draw_map(m, scale=0.2):
# draw a shaded-relief image
im1 = m.shadedrelief(scale=scale)
# print(im1, vars(im1))
# print(f'{dir(im1) = }')
# lats and longs are returned as a dictionary
lats = m.drawparallels(np.linspace(-90, 90, 13))
lons = m.drawmeridians(np.linspace(-180, 180, 13))
# keys contain the plt.Line2D instances
lat_lines = chain(*(tup[1][0] for tup in lats.items()))
lon_lines = chain(*(tup[1][0] for tup in lons.items()))
all_lines = chain(lat_lines, lon_lines)
# cycle through these lines and set the desired style
for line in all_lines:
line.set(linestyle='-', alpha=0.3, color='w')
fig = plt.figure(figsize=(8, 6), edgecolor='w')
m = Basemap(projection='moll', resolution=None,
lat_0=0, lon_0=0)
draw_map(m)
当我试图绘制它时,我得到了没有地球背景图像的空白输出:
预期输出:
据我搜索,我找不到这个问题的解决方案
据我所见,底图中的每个地理投影方法都会发生此问题,例如bluemarble,shadedrelief
我在 VS Code 的 Jupyter Notebook 中使用 Python v3.11.0 运行这段代码
我在 Google Colab 中也得到了相同的输出,安装了 mpltoolkits 和底图
即使我在单独的 Python 文件中运行它也有相同的输出
【问题讨论】:
标签: python-3.x jupyter-notebook data-science matplotlib-basemap map-projections