<jupyter_start><jupyter_text>2D Interpolation<jupyter_code>%matplotlib notebook
import numpy as np
import matplotlib.pyplot as plt
def func(x, y):
    return (x+y)*np.exp(-2.0*(x**2 + y**2))
x, y = np.mgrid[-1:1:25j, -1:1:25j]
fval = func(x, y)
plt.pcolormesh(x, y, fval, cmap='rainbow')
plt.show()
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, fval)
%matplotlib --list
#For pop-up plots you need to restart the notebook kernel 
%matplotlib notebook
#Reimport the module
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
sf = ax.plot_surface(x, y, fval, cmap='jet')
fig.colorbar(sf, shrink=0.5)
%matplotlib inline
plt.pcolormesh(x, y, fval, cmap='rainbow')
plt.show()
#Example for the mapping: ypu now want to either sample the surface or to increase the number of points
xi, yi = np.mgrid[-1:1:5j, -1:1:5j]
plt.pcolormesh(x, y, fval, cmap='rainbow')
plt.scatter(xi, yi)
plt.show()
from scipy import interpolate
f = interpolate.interp2d(x, y, fval, kind='cubic')
%matplotlib inline
xn = np.arange(-1, 1, 0.01)
yn = np.arange(-1, 1, 0.01)
plt.pcolormesh(xn, yn, f(xn, yn), cmap='rainbow')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16, 'fraction_numerical': 0.0336, 'mean_word_length': 5.515625, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '629654', 'license': 'MIT', 'n_tokens_mistral': 562, 'n_tokens_neox': 538, 'n_words': 136, 'path': '03 - 2D Interpolation.ipynb', 'repo_name': 'guimarais/dapc', 'size': '1250'}