python - 减小 basemap 中使用的标记的大小并获得全屏

标签 python matplotlib matplotlib-basemap

我想在德国 map 上绘制大约 7000 个点。我对德国的点很感兴趣,其他点就没那么感兴趣了。如何才能做得更好,以便您能看到更多?

最好是全屏绘图(水平绘图而不是垂直绘图),并且点需要更小。如果有德国的子州也很好。但我不知道这是怎么回事。

这是它现在的样子。 enter image description here

这是代码。其中只有一些样本点,真正的点是从文件中检索的。但这显示了基本代码。

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np


plt.figure(1)
map = Basemap(projection='merc',
resolution='l',
llcrnrlat=44.0,
llcrnrlon=5.0,
urcrnrlat=57.0,
urcrnrlon=17)
map.drawcoastlines()
map.drawcountries()
map.fillcontinents(color='lightgray')
map.drawmapboundary()

long1 = np.array([ 13.404954,  11.581981,   9.993682,   8.682127,   6.960279,
6.773456,   9.182932,  12.373075,  13.737262,  11.07675 ,
7.465298,   7.011555,  12.099147,   9.73201 ,   7.628279,
8.801694,  10.52677 ,   8.466039,   8.239761,  10.89779 ,
8.403653,   8.532471,   7.098207,   7.216236,   9.987608,
7.626135,  11.627624,   6.852038,  10.686559,   8.047179,
8.247253,   6.083887,   7.588996,   9.953355,  10.122765])

lat1 = np.array([ 52.520007,  48.135125,  53.551085,  50.110922,  50.937531,
51.227741,  48.775846,  51.339695,  51.050409,  49.45203 ,
51.513587,  51.455643,  54.092441,  52.375892,  51.36591 ,
53.079296,  52.268874,  49.487459,  50.078218,  48.370545,
49.00689 ,  52.030228,  50.73743 ,  51.481845,  48.401082,
51.960665,  52.120533,  51.47512 ,  53.865467,  52.279911,
49.992862,  50.775346,  50.356943,  49.791304,  54.323293])

x, y = map(long1, lat1)
map.plot(x,y,'o')
plt.show()

最佳答案

这是几个问题,最好把它们分开。

与此同时,Evan Mosseri 已经回答了关于标记大小的问题。另一种方法是简单地使用点标记,正如我将展示的那样。他还展示了如何最大化图形,我将使用另一种方法,即图形的大小只是预定义的。

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

fig = plt.figure(figsize=(20,10))  # predefined figure size, change to your liking. 
# But doesn't matter if you save to any vector graphics format though (e.g. pdf)
ax = fig.add_axes([0.05,0.05,0.9,0.85])

# These coordinates form the bounding box of Germany
bot, top, left, right = 5.87, 15.04, 47.26, 55.06 # just to zoom in to only Germany
map = Basemap(projection='merc', resolution='l',
    llcrnrlat=left,
    llcrnrlon=bot,
    urcrnrlat=right,
    urcrnrlon=top)
map.readshapefile('./DEU_adm/DEU_adm1', 'adm_1', drawbounds=True)  # plots the state boundaries, read explanation below code
map.drawcoastlines()
map.fillcontinents(color='lightgray')

long1 = np.array([ 13.404954,  11.581981,   9.993682,   8.682127,   6.960279,
6.773456,   9.182932,  12.373075,  13.737262,  11.07675 ,
7.465298,   7.011555,  12.099147,   9.73201 ,   7.628279,
8.801694,  10.52677 ,   8.466039,   8.239761,  10.89779 ,
8.403653,   8.532471,   7.098207,   7.216236,   9.987608,
7.626135,  11.627624,   6.852038,  10.686559,   8.047179,
8.247253,   6.083887,   7.588996,   9.953355,  10.122765])

lat1 = np.array([ 52.520007,  48.135125,  53.551085,  50.110922,  50.937531,
51.227741,  48.775846,  51.339695,  51.050409,  49.45203 ,
51.513587,  51.455643,  54.092441,  52.375892,  51.36591 ,
53.079296,  52.268874,  49.487459,  50.078218,  48.370545,
49.00689 ,  52.030228,  50.73743 ,  51.481845,  48.401082,
51.960665,  52.120533,  51.47512 ,  53.865467,  52.279911,
49.992862,  50.775346,  50.356943,  49.791304,  54.323293])

x, y = map(long1, lat1)
map.plot(x,y,'.')  # Use the dot-marker or use a different marker, but specify the `markersize`.

作为状态基础的数据是从 shapefile 中获得的。这些可以从例如获得。 Global Administrative Areas(本网站的只能用于非商业用途)

这将导致:

basemap projection of Germany with states .

关于最后一个问题:如果数组 latlong 中的坐标不在德国境内,则必须将它们过滤掉。一种方法是使用 geocoder 模块,传入 (lat, lon) 并检查返回的结果是否包含字典键值对 “country”: “德国”

关于python - 减小 basemap 中使用的标记的大小并获得全屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28181415/

相关文章:

python - 无法将输入发送到 Sublime Text 中正在运行的程序

python - 使用opencv dnn readNetFromModelOptimizer时发生错误(预期: 'inputShapeLimitation.size() == blobShape.size()')

python - 导入多数组 Numpy 扩展模块失败 Visual Studio 2019 Anaconda 1.9.6 Python 3.7.1

python - 使用离散变量的二维离散彩色图

python:拉伸(stretch)世界地图

python - 在 matplotlib basemap 正射投影中更改图像背景颜色

C#:使用 Python.Runtime 未找到

matplotlib - 来自脚本的 Julia pyplot(非交互式)

python - 如何使用python将RGB多波段GeoTIFF投影到指定区域范围?

python - 在带有 QT4 的 Python 中使用像素图或图像序列制作动画