How to plot property distribution with interpolation?

Question:

I have a dataframe like this:

import random
import matplotlib.pyplot as plt
plt.style.use('ggplot')
fig = plt.figure(figsize=(16,8))
import pandas as pd

data = pd.DataFrame({"X":random.sample(range(530000, 560000), 60),
                     "Y":random.sample(range(8580000, 8620000), 60),
                     "PROPERTY":random.choices(range(0, 30), k=60)})

I saw an example where I could plot my PROPERTY along X and Y coordinates as a triangle spatial distribution:

x = data["X"]
y = data["Y"]
z = data["PROPERTY"]

# Plot Triangular Color Filled Contour
plt.tricontourf(x, y, z, cmap="rainbow")
plt.colorbar()
plt.tricontour(x, y, z)

# Set well shapes
plt.scatter(x, y, color='black')
plt.xlabel("X")
plt.ylabel("Y")

enter image description here

Althoug I would like to plot it as a different map type, not with these abrupt data transitions. Maybe like kriging or smooth interpolation like this example:

enter image description here

Anyone could show me an example?

Asked By: user026

||

Answers:

I used the pykrige package to interpolate the point data into a grid field.

The code and output figure are here.

import random
import matplotlib.pyplot as plt
plt.style.use('ggplot')
fig = plt.figure(figsize=(6,4))
import pandas as pd
from pykrige import OrdinaryKriging
import numpy as np

random.seed(100)
data = pd.DataFrame({"X":random.sample(range(530000, 560000), 60),
                     "Y":random.sample(range(8580000, 8620000), 60),
                     "PROPERTY":random.choices(range(0, 30), k=60)})

x = data["X"]
y = data["Y"]
z = data["PROPERTY"]

x1 = np.linspace(530000.,560000,700)
y1 = np.linspace(8580000,8620000,400)


dict1=  {'sill': 1, 'range': 6500.0, 'nugget': .1}
OK = OrdinaryKriging(x,y,z,variogram_model='gaussian',
                     variogram_parameters=dict1,nlags=6)
zgrid,ss = OK.execute('grid',x1,y1)

xgrid,ygrid = np.meshgrid(x1,y1)

# Plot Triangular Color Filled Contour
# plt.tricontourf(x, y, z, cmap="rainbow")

plt.contourf(xgrid, ygrid, zgrid, cmap="rainbow")
plt.colorbar()

# Set well shapes
plt.scatter(x, y, color='black')
plt.xlabel("X")
plt.ylabel("Y")

enter image description here

Answered By: Li Yupeng