Python 减小底图中使用的标记的大小并获得全屏显示
我想在德国地图上画大约7000个点。我对德国的几点很感兴趣,其他几点就不那么有趣了。如何使这一点变得更好,以便您可以看到更多 最好是全屏打印(水平打印而不是垂直打印),并且点需要更小。如果有德国的附属国也会很好。但我不知道这是怎么回事 这是它现在的样子。 这是代码。其中只有一些样本点,实际点是从文件中检索的。但这显示了基本代码Python 减小底图中使用的标记的大小并获得全屏显示,python,matplotlib,matplotlib-basemap,Python,Matplotlib,Matplotlib Basemap,我想在德国地图上画大约7000个点。我对德国的几点很感兴趣,其他几点就不那么有趣了。如何使这一点变得更好,以便您可以看到更多 最好是全屏打印(水平打印而不是垂直打印),并且点需要更小。如果有德国的附属国也会很好。但我不知道这是怎么回事 这是它现在的样子。 这是代码。其中只有一些样本点,实际点是从文件中检索的。但这显示了基本代码 from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import nump
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()之前也添加此项:
如果我理解了您试图正确执行的操作,那么应该非常简单:
map.plot(x,y,'o',markersize=2)
或者任何你想要的标记
在plt.show()之前也添加此项:
这是几个问题,最好把它们分开 与此同时,埃文·莫塞里已经回答了关于马克赛斯的问题。另一种方法是简单地使用点标记,正如我将要展示的那样。他还展示了如何最大化图形,我将使用另一种方法,即图形的大小只是预定义的
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`.
状态的基础数据是从形状文件中获得的。这些信息可从以下网站获得(本网站提供的信息只能用于非商业目的)
这将导致:
至于最后一个问题:如果数组
lat
和long
中的坐标不在德国境内,则必须将它们过滤掉。您可以这样做的一种方法是使用模块,传入(lat,lon)
,并检查返回的结果是否包含字典键值对“country”:“Germany”
这是几个问题,最好将它们分开
与此同时,埃文·莫塞里已经回答了关于马克赛斯的问题。另一种方法是简单地使用点标记,正如我将要展示的那样。他还展示了如何最大化图形,我将使用另一种方法,即图形的大小只是预定义的
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`.
状态的基础数据是从形状文件中获得的。这些信息可从以下网站获得(本网站提供的信息只能用于非商业目的)
这将导致:
至于最后一个问题:如果数组
lat
和long
中的坐标不在德国境内,则必须将它们过滤掉。一种方法是使用模块,传入(lat,lon)
,并检查返回的结果是否包含字典键值对“country”:“Germany”
非常好!我怎样才能给德国旁边的其他国家一个不同的颜色呢?请作为一个新问题来问,这对使用搜索功能的人来说更有用。非常好!我怎样才能给德国旁边的其他国家一个不同的颜色?请作为一个新问题提问,这对使用搜索功能的人更有用。