代码优先:
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
ax = plt.axes(projection=ccrs.Mercator())
ax.set_extent([72, 135, 18, 53])
ax.annotate('hello', xy=(100, 49), xycoords='data',
transform=ccrs.PlateCarree(), zorder=12)
plt.show()
Run Code Online (Sandbox Code Playgroud)
结果不是预期的结果,我对我的方法有其他怀疑.所以我的问题是:
如果我想绘制地图看起来像网络地图(例如谷歌地图).地图区域可能与中国一样大,大部分都不是全球性的.谷歌搜索后,这些网站大多使用"网络墨卡托"投影.所以我想我应该plt.axes(projection=ccrs.Mercator()在这里使用,我是对的吗?或者如果我错了我该怎么用?
我想绘制的坐标数据类似于121°E,49°N(在绘制航线之前将度数转换为十进制),未投影,WGS84坐标系统,可能来自GPS.我有权使用transform=ccrs.PlateCarree()吗?或者如果我错了我该怎么用?
在annotate上述说明不了什么.在对该ax.set_extent行进行注释之后,将"hello"文本绘制在零(0,0)点处.我想要的是在点(100°E,49°N)如何纠正这个?
我有两个shapefile.一个是点特征shapefile,名为"point.shp",另一个是名为"polygon.shp"的多边形shapefile.我想用cartopy添加到地图.我设法添加"polygon.shp",但失败了"point.shp".
这是我的代码:
import matplotlib.pyplot as plt
from cartopy import crs
from cartopy.io.shapereader import Reader
from cartopy.feature import ShapelyFeature
ax = plt.axes(projection=crs.PlateCarree())
# add the polygon file, worked
ax.add_geometries(Reader("polygon.shp").geometries(), crs.PlateCarree(), facecolor='w')
# or(also worked):
ax.add_feature(ShapelyFeature(Reader("polygon.shp").geometries(), crs.PlateCarree(), facecolor='r'))
# but these two ways both failed with the "point.shp"
ax.add_geometries(Reader("point.shp").geometries(), crs.PlateCarree())
# or, this doesn't work neither:
ax.add_feature(ShapelyFeature(Reader("polygon.shp").geometries(), crs.PlateCarree(), facecolor='r'))
Run Code Online (Sandbox Code Playgroud)
有没有人知道如何做到这一点,或为什么,没有检索所有点'x,y coords然后绘制它们?
并且坐标(x,y值),ax.plot()工作,但ax.scatter()失败,为什么?
谢谢
我有一个目录格式应用程序,命名myapp如下:
myapp/
|
+ -- main.py
+ -- favicon.ico
+ -- static
|
+ -- some.img
Run Code Online (Sandbox Code Playgroud)
如果我跑bokeh serve myapp,我会一直跑404 GET /favicon.ico (::1)。
我应该放在哪里favicon.ico?
我想在第一个轴的右上角添加第二个轴。谷歌搜索后,我找到了两种方法来做这样的事情:fig.add_axes(), 和mpl_toolkits.axes_grid.inset_locator.inset_axes. 但fig.add_axes()不接受transformarg。所以下面的代码会抛出一个错误。所以位置不能在父轴坐标下,而是在图形坐标下。
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
fig, ax = plt.subplots(1, 1, subplot_kw={'projection': ccrs.PlateCarree()})
ax2 = fig.add_axes([0.8, 0, 0.2, 0.2], transform=ax.transAxes, projection=ccrs.PlateCarree())
Run Code Online (Sandbox Code Playgroud)
并且inset_axes()不接受projectionarg,所以我不能添加ax2为 cartopy geo-axes。
from mpl_toolkits.axes_grid.inset_locator import inset_axes
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
fig, ax = plt.subplots(1, 1, subplot_kw={'projection': ccrs.PlateCarree()})
# The following line doesn't work
ax2 = inset_axes(ax, width='20%', height='20%', axes_kwargs={'projection': ccrs.PlateCarree()})
# Doesn't work neither:
ax2 …Run Code Online (Sandbox Code Playgroud)