plot_contour 2¶

Query¶

import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

"""
Create matrix of ones
"""
a = np.ones((5,10))
# end

"""
Plot a filled contour plot from energy_data
Plot contour lines on top
Add a color bar 
Save to contour.png
"""

def energy(x,y):
    return 0.5*(x**2+np.sin(y*5))

x = np.arange(-3,3,0.1)
y = np.arange(-3,3,0.1)
X, Y = np.meshgrid(x,y)

energy_data = energy(X,Y)

Output¶

import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

"""
Create matrix of ones
"""
a = np.ones((5,10))
# end

"""
Plot a filled contour plot from energy_data
Plot contour lines on top
Add a color bar 
Save to contour.png
"""

def energy(x,y):
    return 0.5*(x**2+np.sin(y*5))

x = np.arange(-3,3,0.1)
y = np.arange(-3,3,0.1)
X, Y = np.meshgrid(x,y)

energy_data = energy(X,Y)

plt.contourf(X,Y,energy_data)
plt.contour(X,Y,energy_data)
plt.colorbar()
plt.savefig('contour.png')

Evaluate¶

Go to Google Form