Gridded numpy arrays

This example demonstrates how to plot numpy arrays of data on a map, given the longitude and latitude arrays which describe each point.

[1]:
import numpy as np

import earthkit.plots

data = np.random.rand(15, 30)

y = np.linspace(-90, 90, 15)
x = np.linspace(-180, 180, 30)

We can plot this as grid cells:

[2]:
chart = earthkit.plots.Map()

chart.grid_cells(data, x=x, y=y)

chart.coastlines(color="white")
chart.gridlines()
chart.legend(label="")
chart.show()
../../../_images/examples_gallery_gridded-data_numpy-arrays_4_0.png

Or as isobands (smooth contours):

[3]:
chart = earthkit.plots.Map()

chart.contourf(data, x=x, y=y)

chart.coastlines(color="white")
chart.gridlines()
chart.legend(label="")
chart.show()
../../../_images/examples_gallery_gridded-data_numpy-arrays_6_0.png

Or as a point cloud:

[4]:
chart = earthkit.plots.Map()

chart.point_cloud(data, x=x, y=y)

chart.coastlines()
chart.gridlines()
chart.legend(label="")
chart.show()
../../../_images/examples_gallery_gridded-data_numpy-arrays_8_0.png

You can of course also plot your data on any projection:

[5]:
chart = earthkit.plots.Map(crs="Robinson")

chart.grid_cells(data, x=x, y=y)

chart.coastlines(color="white")
chart.gridlines()
chart.legend(label="")
chart.show()
../../../_images/examples_gallery_gridded-data_numpy-arrays_10_0.png