简体   繁体   English

使用 cartopy 到 plot 一个二进制 map 的地球

[英]Using cartopy to plot a binary map of Earth

I'm trying to use cartopy to plot a map of Earth with only 2 colors.我正在尝试对地球的 plot 和 map 使用 cartopy,只有 2 个 colors。 The lands, filled in white and the ocean in dark for example.例如,被白色填充的土地和在黑暗中填充的海洋。 For now, I use the coastlines() method that creates the contour of the continents, but i don't know how to fill them with a colour, or to fill the ocean with one.现在,我使用创建大陆轮廓的 Coastlines() 方法,但我不知道如何用颜色填充它们,或者用一种颜色填充海洋。

 import matplotlib.pyplot as plt

 fig = plt.figure(figsize=(12,6))
 ax = fig.add_subplot(1,1,1,projection = ccrs.EckertIV())
 ax.clear()
 cs = ax.contourf(longitude,lattitude,A,transform=ccrs.PlateCarree(),
    cmap='gist_gray',alpha=0.3)#,extend = 'both')
 ax.coastlines(color = 'black')

It produces a map with the continents, but it is all white, except the coastlines in black.它产生一个带有大陆的 map,但它全是白色的,除了黑色的海岸线。 Any thoughts on how to fill continents and/or oceans with a color?关于如何用颜色填充大陆和/或海洋的任何想法? I've thought about using the stock_img() method but it does not uniformly fill the land with one colour.我考虑过使用 stock_img() 方法,但它并没有用一种颜色均匀地填充土地。

Thank you in advance !先感谢您 !

PS: this is my first post so please tell me if you need more precision on my problem or if I need to edit my post in a certain way PS:这是我的第一篇文章,所以请告诉我您是否需要更精确地解决我的问题,或者我是否需要以某种方式编辑我的帖子

Here is a minimal example.这是一个最小的例子。 In your example, you didn't show what is your longitude , latitude and A data, so I just replaced with a simple line.在您的示例中,您没有显示您的longitudelatitudeA数据,所以我只是用一条简单的线替换。

import matplotlib.pyplot as plt
import cartopy
import cartopy.crs as ccrs

latitude = [0, 10]
longitude = [0, 20]

fig = plt.figure(figsize=(12, 6))
ax = fig.add_subplot(1, 1, 1, projection=ccrs.EckertIV())

ax.set_global()
# set_extent([-180, 180, -90, 90], crs=ccrs.PlateCarree())

ax.patch.set_facecolor(color='black')
# or
# ax.background_patch.set_facecolor(color='black')   # cartopy < v0.18
# or
# ax.add_feature(cartopy.feature.OCEAN, color='black')

ax.add_feature(cartopy.feature.LAND, color='white')

ax.plot(longitude, latitude, color='red', transform=ccrs.PlateCarree())

You are using an EckertIV projection, so you have to inform the axis that your longitude and latitude values are referenced to a PlateCarree projection.您正在使用 EckertIV 投影,因此您必须通知轴您的经度和纬度值参考PlateCarree投影。 That's why you have to use the crs kw in set_extent (if not using set_global ) and the transform kw in plot .这就是为什么您必须使用set_extent中的crs kw (如果不使用set_global )和plot中的transform kw 的原因。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何使用 cartopy 和 ZF620113237AEEZ56E 来自“natural_earth”的 map 上的 csv 中的 plot 坐标? - How do I plot coordinates in csv on the map from from 'natural_earth" using cartopy and matplotlib? 如何为 map 上的某些引用添加 plot 标签? 使用卡托比 - How to plot labels for some cites on the map? using cartopy 如何在cartopy地图中绘制间隔? - How to plot intervals in a cartopy map? 在世界地图上绘制分类数据(cartopy/matplotlib) - Plot categorical data on world map (cartopy/matplotlib) 在Cartopy地图上绘制shapefile城市边界 - Plot shapefile city borders on top of cartopy map 为什么散点图不能在cartopy创建的地图上 - why the scatter plot can not be on the map created by cartopy 使用 Cartopy (Python) 制作正交 plot 时,如何裁剪 map / 设置图像的纬度/经度边界? - When using Cartopy (Python) to make Orthographic plot, how to crop the map / set the latitude/longitude boundaries of image? Python:如何在cartopy地图上的特定点绘制散点图? - Python: How to plot scatter plot at specific point on map in cartopy? 放大 cartopy map 并添加海洋特征会将整个 plot 变为蓝色? - Zooming in on cartopy map and adding the ocean feature changes the entire plot to blue? 我如何使用带有 Cartopy 的单个调色板在同一个 map 上使用 plot 2 个变量? - How do I plot 2 variables on the same map with a single palette with Cartopy?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM