import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
"""
Create matrix of ones
"""
a = np.ones((5,10))
# end
"""
First plot y = x
Now plot y = sin(x) on a second y axis
Make the x range 0 to 4 pi
Save to dual.png
"""
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
"""
Create matrix of ones
"""
a = np.ones((5,10))
# end
"""
First plot y = x
Now plot y = sin(x) on a second y axis
Make the x range 0 to 4 pi
Save to dual.png
"""
x = np.linspace(0, 4*np.pi, 100)
y = np.sin(x)
fig, ax1 = plt.subplots()
ax1.plot(x, x, 'b-')
ax1.set_xlabel('x')
ax1.set_ylabel('y', color='b')
ax1.tick_params('y', colors='b')
ax2 = ax1.twinx()
ax2.plot(x, y, 'r.')
ax2.set_ylabel('y', color='r')
ax2.tick_params('y', colors='r')
fig.tight_layout()
plt.savefig('dual.png')
Go to Google Form