I have scattered data and I am interpolating it to gridded data. Afterwards I draw everything with the contourf function. In the end I just want to draw everything inside a defined circle. Everything else should be white, but I don"t know how to achieve this. Is there a simple way to do this?
Here is my code:
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import griddata
def func(x, y):
return x*(1-x)*np.cos(4*np.pi*x) * np.sin(4*np.pi*y**2)**2
grid_x, grid_y = np.mgrid[0:1:100j, 0:1:200j]
points = np.random.rand(1000, 2)
values = func(points[:,0], points[:,1])
grid_z0 = griddata(points, values, (grid_x, grid_y), method='nearest')
plt.contourf(grid_x,grid_y,grid_z0)
plt.savefig("plot_data_in_circle.png")
Edit: I attach the plot which comes out from my code:
And this is how it should look like:
– Jan SE Apr 30 '18 at 12:59