# How to make two plots on a different scale

I have two plots that I need to represent on the same graph. Here is a mwe. I can scale q2 down, but ideally I would like to have a y-axis on the left representing q1 values and another y-axis on the right representing q2 values. How can I do that?

phi = var('phi')
a=2
q1=a*phi^2+1
q2=a*phi^2+2000
t1=q1.plot(aspect_ratio=1,xmin=0,xmax=10)
t2=q2.plot(aspect_ratio=1,xmin=0,xmax=10)
z=t1+t2
z.show(xmin=0,xmax=10,ymin=0,ymax=300,aspect_ratio=.02)

edit retag close merge delete

Sort by » oldest newest most voted I am afraid you have to do some programming For example:

def y2_axis(x,y1,y2,y3,d=50):
G = line([(x,0),(x,y2-y1)],color='red')
G += text(str(y2), (x*1.03,y1),color='red',horizontal_alignment='left')
G += text(str(y3), (x*1.03,y1+y3-y2),color='red',horizontal_alignment='left')
yd = d
while yd < y3-y2:
G += line([(x,y1+yd),(x*1.01,y1+yd)],color='red')
G += text(str(y2+yd), (x*1.03,y1+yd),color='red',horizontal_alignment='left')
yd += d
return G

phi = var('phi')
a=2
q1=a*phi^2+1
q2=a*phi^2 #+2000
t1=q1.plot(aspect_ratio=1,xmin=0,xmax=10,thickness=2)
t2=q2.plot(aspect_ratio=1,xmin=0,xmax=10,thickness=2,linestyle='--',color='red')
z=t1+t2
z += y2_axis(10,0,2000,2300)
z.show(xmin=0,xmax=10,ymin=0,ymax=300,aspect_ratio=0.02)

more