Cartopy-使用;人口稠密的地方;Matplotlib地图上的自然学习功能显示

Cartopy-使用;人口稠密的地方;Matplotlib地图上的自然学习功能显示,matplotlib,jupyter-notebook,cartopy,Matplotlib,Jupyter Notebook,Cartopy,我正在制作一张地图,需要城市名称和州名称(巴西和哥伦比亚)的参考点和标签。从Natural Earth网页中的web图像中可以看出,“populated_places”功能将满足我的需要。我只需要知道如何使用它 在代码中,我有以下内容: import cartopy.feature as cf pop = cf.NaturalEarthFeature(category='cultural', name='populated_places', scale='10m',

我正在制作一张地图,需要城市名称和州名称(巴西和哥伦比亚)的参考点和标签。从Natural Earth网页中的web图像中可以看出,“populated_places”功能将满足我的需要。我只需要知道如何使用它

在代码中,我有以下内容:

import cartopy.feature as cf
pop = cf.NaturalEarthFeature(category='cultural',
      name='populated_places', 
      scale='10m', 
      facecolor='none')    
这部分看起来正在工作,因为没有给我任何错误或警告


之后,我尝试使用:
ax1.scatter('pop.LATITUDE','pop.LONGITUDE',projection=ccrs.PlateCarree())

我得到的属性错误如下:

错误与第一段和标题无关。查看有关如何在cartopy中绘制某些内容的文档。最好从一个已知的例子开始,然后只修改输入数据。谢谢你的回答。我一直在研究你的建议(请编辑今天的问题)。我至少成功地以正确的方式绘制了数据。但是仍然有一些差距来标记它,国家和城市名称,以及如何根据人口来给点上色。你可以把你需要的东西(在上面的评论中)作为一个新问题发布。然后,更多的人将看到和帮助。好的,再次tks。以下是我想解决的两个问题:绘制城市名称,并根据人口数量逐渐确定城市位置的符号大小。错误与第一段和标题无关。查看有关如何在cartopy中绘制某些内容的文档。最好从一个已知的例子开始,然后只修改输入数据。谢谢你的回答。我一直在研究你的建议(请编辑今天的问题)。我至少成功地以正确的方式绘制了数据。但是仍然有一些差距来标记它,国家和城市名称,以及如何根据人口来给点上色。你可以把你需要的东西(在上面的评论中)作为一个新问题发布。然后,更多的人将看到和帮助。好的,再次tks。以下是我想解决的两个问题:绘制城市名称,并根据人口数量逐渐确定城市位置的符号大小。
AttributeError                            Traceback (most recent call last)
<ipython-input-4-47ca7f66b91e> in <module>
     19 ax1.add_feature(stt, edgecolor='black',facecolor='none')
     20 ax1.add_feature(stt_prv, linewidth=0.5, edgecolor='gray')
---> 21 ax1.scatter('pop.LATITUDE', 'pop.LONGITUDE', projection=ccrs.PlateCarree())
     22 
     23 # ax1.add_feature(cartopy.feature.LAND)

C:\ProgramData\Anaconda3\lib\site-packages\cartopy\mpl\geoaxes.py in scatter(self, *args, **kwargs)
   1435                              '(PlateCarree or RotatedPole).')
   1436 
-> 1437         result = matplotlib.axes.Axes.scatter(self, *args, **kwargs)
   1438         self.autoscale_view()
   1439         return result

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, data, *args, **kwargs)
   1808                         "the Matplotlib list!)" % (label_namer, func.__name__),
   1809                         RuntimeWarning, stacklevel=2)
-> 1810             return func(ax, *args, **kwargs)
   1811 
   1812         inner.__doc__ = _add_data_doc(inner.__doc__,

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs)
   4298                 )
   4299         collection.set_transform(mtransforms.IdentityTransform())
-> 4300         collection.update(kwargs)
   4301 
   4302         if colors is None:

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\artist.py in update(self, props)
    914 
    915         with cbook._setattr_cm(self, eventson=False):
--> 916             ret = [_update_property(self, k, v) for k, v in props.items()]
    917 
    918         if len(ret):

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\artist.py in <listcomp>(.0)
    914 
    915         with cbook._setattr_cm(self, eventson=False):
--> 916             ret = [_update_property(self, k, v) for k, v in props.items()]
    917 
    918         if len(ret):

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\artist.py in _update_property(self, k, v)
    910                 func = getattr(self, 'set_' + k, None)
    911                 if not callable(func):
--> 912                     raise AttributeError('Unknown property %s' % k)
    913                 return func(v)
    914 

AttributeError: Unknown property projection
%matplotlib inline
import matplotlib.pyplot as plt
import cartopy
import cartopy.crs as ccrs
import cartopy.feature as cf
import cartopy.io.shapereader as shpr

# Retriving the information from web
stt = cf.NaturalEarthFeature(category='cultural', 
    name='admin_0_boundary_lines_land',
    scale='10m',facecolor='none')
stt_prv = cf.NaturalEarthFeature(category='cultural', 
    name='admin_1_states_provinces_lines',
    scale='10m',facecolor='none')
fname = shpr.natural_earth(resolution='10m', category='cultural', name='populated_places')
reader = shpr.Reader(fname)

# Image desing
fig = plt.figure(figsize=(15, 6))

# Main Map
ax = fig.add_subplot(1, 5, (1,4), projection=ccrs.PlateCarree())
ax.set_title('Populated places of the world', fontsize=16)
ax.coastlines()
points = list(reader.geometries())
ax.scatter([point.x for point in points],
           [point.y for point in points],
           transform=ccrs.PlateCarree(),
           s=0.1, c='r')
ax.add_feature(stt, linewidth=0.2, edgecolor='black')

# Brazil Map
ax = fig.add_subplot(2, 5, 5, projection=ccrs.PlateCarree())
ax.set_extent([-74, -34, -30, 6.1])
ax.set_title('Populated places of BRA', fontsize=8)
ax.coastlines()
points = list(reader.geometries())
ax.scatter([point.x for point in points],
           [point.y for point in points],
           transform=ccrs.PlateCarree(),
           marker='p',s=10, c='r')
ax.add_feature(stt,     linewidth=0.5, edgecolor='black')
ax.add_feature(stt_prv, linewidth=0.2, edgecolor='black')

# Colombia Map
ax = fig.add_subplot(2, 5, 10, projection=ccrs.PlateCarree())
ax.set_extent([-65, -80, -5, 13])
ax.set_title('Populated places of COL', fontsize=8)
ax.coastlines()
points = list(reader.geometries())
ax.scatter([point.x for point in points],
           [point.y for point in points],
           transform=ccrs.PlateCarree(),
           marker='p',s=10, c='r')
ax.add_feature(stt,     linewidth=0.5, edgecolor='black', zorder=0)
ax.add_feature(stt_prv, linewidth=0.2, edgecolor='black', zorder=5)

plt.show()