Data-Science-Regular-Bootcamp icon indicating copy to clipboard operation
Data-Science-Regular-Bootcamp copied to clipboard

Matplotlib - Twin Axes

Open imsanjoykb opened this issue 3 years ago • 0 comments

import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
a1 = fig.add_axes([0,0,1,1])
x = np.arange(1,11)
a1.plot(x,np.exp(x))
a1.set_ylabel('exp')
a2 = a1.twinx()
a2.plot(x, np.log(x),'ro-')
a2.set_ylabel('log')
fig.legend(labels = ('exp','log'),loc='upper left')
plt.show()

imsanjoykb avatar Feb 07 '22 16:02 imsanjoykb