减小底图中使用的标记的大小并获得全屏

decrease size of markers used in basemap and get fullscreen

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

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

这是它现在的样子。

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

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()

如果我理解你正在尝试做的事情是正确的,它应该很简单:map.plot(x,y,'o',markersize=2) 或者你想要的任何标记大小

plt.show():

之前也加上这个
mng = plt.get_current_fig_manager()
mng.frame.Maximize(True)

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

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

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(本网站的只能用于non-commercial目的

这将导致:

.

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