-1

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?

user026
  • 638
  • 4
  • 14
  • Could you post a sample of your dataset. Have you considered to use https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.LinearNDInterpolator.html? – jlandercy Sep 20 '22 at 13:19
  • @jlandercy, sorry but this linear interpolation it is kind of abrupt as well. I wrote an example on my question with the dataframe "data". I tried with your recommendation but it didn't worked well – user026 Sep 20 '22 at 13:44
  • See also [this tutorial example](https://matplotlib.org/stable/gallery/images_contours_and_fields/tricontour_smooth_user.html) or [How to smooth matplotlib contour plot?](https://stackoverflow.com/questions/12274529/how-to-smooth-matplotlib-contour-plot) – JohanC Sep 20 '22 at 14:32

1 Answers1

2

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

Li Yupeng
  • 721
  • 4
  • 9