4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

cartopyやってみた。

Posted at

概要

cartpyやってみた。

サンプルコード

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

ax = plt.axes(projection = ccrs.PlateCarree(central_longitude = 140.0))
ax.coastlines()
ax.stock_img()
plt.savefig("cartopy0.png")
plt.show()

cartopy0.png

サンプルコード

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


ax = plt.axes(projection = ccrs.Robinson(central_longitude = 140.0))
ax.set_global()
ax.stock_img()
ax.coastlines()
plt.plot(-0.08, 51.53, 'o', transform = ccrs.PlateCarree())
plt.plot([-0.08, 132], [51.53, 43.17], transform = ccrs.PlateCarree())
plt.plot([-0.08, 132], [51.53, 43.17], transform = ccrs.Geodetic())
plt.savefig("cartopy1.png")
plt.show()

cartopy1.png

サンプルコード

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

def sample_data(shape = (20, 30)):
    crs = ccrs.RotatedPole(pole_longitude = 177.5, pole_latitude = 37.5)
    x = np.linspace(311.9, 391.1, shape[1])
    y = np.linspace(-23.6, 24.8, shape[0])
    x2d, y2d = np.meshgrid(x, y)
    u = 10 * (2 * np.cos(2 * np.deg2rad(x2d) + 3 * np.deg2rad(y2d + 30)) ** 2)
    v = 20 * np.cos(6 * np.deg2rad(x2d))
    return x, y, u, v, crs

def main():
    ax = plt.axes(projection = ccrs.Orthographic(-10, 45))
    ax.add_feature(cartopy.feature.OCEAN, zorder = 0)
    ax.add_feature(cartopy.feature.LAND, zorder = 0, edgecolor = 'black')
    ax.set_global()
    ax.gridlines()
    x, y, u, v, vector_crs = sample_data()
    ax.quiver(x, y, u, v, transform=vector_crs)
    plt.savefig("cartopy2.png")
    plt.show()

if __name__ == '__main__':
    main()

cartopy2.png

以上。

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?