<jupyter_start><jupyter_text>VISUALIZING A 3-D FUNCTION<jupyter_code>## set up a function z = f(x,y) for contour plot
def f(x, y):
    return np.sin(x) ** 10 + np.cos(10 + y * x) * np.cos(x)
## Build a 2-d grid
x = np.linspace(0, 5, 50)
y = np.linspace(0, 5, 40)

X, Y = np.meshgrid(x, y)
Z = f(X, Y)

plt.contour(X, Y, Z, colors='black')
plt.contour(X, Y, Z, 20, cmap='RdGy')
## to check the available color maps
plt.cm.<TAB>
## fill the spaces between the lines
plt.contourf(X, Y, Z, 20, cmap='RdGy')
plt.colorbar()

# black regions are peaks; red regions are valleys as per the colorbar<jupyter_output><empty_output><jupyter_text>Image Plots<jupyter_code>## to interpret 2-d data as an image - to avoid splotchiness and have a continuos contour plot instead of discrete when desired
plt.imshow(Z, extent=[0, 5, 0, 5], origin='lower', cmap='RdGy')
plt.colorbar()
plt.axis(aspect='image')<jupyter_output><empty_output><jupyter_text>Combine Contour and Image Plots<jupyter_code>contours = plt.contour(X, Y, Z, 3, colors='black')
plt.clabel(contours, inline=True, fontsize=8)

plt.imshow(Z, extent=[0, 5, 0, 5], origin='lower', cmap='RdGy', alpha=0.5)
plt.colorbar()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1606694560669456, 'fraction_numerical': 0.02594142259414226, 'mean_word_length': 5.571428571428571, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '545102', 'license': 'MIT', 'n_tokens_mistral': 527, 'n_tokens_neox': 486, 'n_words': 134, 'path': 'density_and_contour_plots.ipynb', 'repo_name': 'salma-shaik/viz-mpl-jvp', 'size': '1195'}