hu3b11b7
hu3b11b7

Reputation: 169

How can I use Matplotlib with different axes

Does anyone know how can i draw more lines with matplotlib.pyplot.plot but forcing them to use its own axes?

eg I have data in lists a b c

a is the base of the others (time), so I would like to draw how b and c changes

but b contains big numbers and c contains small numbers, so when i draw both then i can see only b

thanks

Upvotes: 0

Views: 177

Answers (1)

carla
carla

Reputation: 2251

You just have to add a secondary axis to your plot. As an example, this code...

from matplotlib.pyplot import *


#creating some data
a = range(10)
b = [2*x for x in a]
c = [x**10 for x in a]


fig = figure()
ax1 = fig.add_subplot(111)
ax1.set_ylabel('$y = 2 . x$')
ax1.plot(a, b, 'yo')


ax2 = ax1.twinx() #create a twin of Axes for generating a plot
                  # with a share x-axis but independent y axis
ax2.set_ylabel('$y = x^{10}$')
ax2.plot(a,c,'b-')


show()

...will generate this figure: example twinx

Upvotes: 2

Related Questions