Last active
March 6, 2024 09:12
-
-
Save AlexTitovWork/d66584382619e5edba151867e41cba3e to your computer and use it in GitHub Desktop.
Plotting the Himmelblau function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
# ################################################################################ | |
def plot_function(): | |
# Make data. | |
X = np.arange(-5, 5, 0.25) | |
Y = np.arange(-5, 5, 0.25) | |
X, Y = np.meshgrid(X, Y) | |
Z = (X ** 2 + Y - 11) ** 2 + (X + Y ** 2 - 7) ** 2 | |
# Plot the surface. | |
fig = plt.figure() | |
ax = fig.gca(projection='3d') | |
surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm, | |
linewidth=0, antialiased=False) | |
ax.set_xlabel('X Label') | |
ax.set_ylabel('Y Label') | |
ax.set_zlabel('Z Label') | |
return X, Y, Z | |
# ################################################################################ | |
X, Y, Z = plot_function() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perfect ! Thank you for your response and cool code.