我想在德国的地图上画出大约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()
答案 0 :(得分:3)
这些是几个问题,最好将它们分开。
与此同时,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(此网站上的内容仅可用于非商业用途)
这将导致:
至于最后一个问题:如果数组lat
和long
中的坐标不在德国境内,则必须将其过滤掉。一种方法是使用geocoder模块,传入(lat, lon)
并检查返回的结果是否包含字典键值对"country": "Germany"
。
答案 1 :(得分:2)
如果我理解您要正确执行的操作,则应该如下:map.plot(x,y,'o',markersize=2)
或者你想要的任何标记
也会在plt.show():
mng = plt.get_current_fig_manager()
mng.frame.Maximize(True)