Ask Your Question
1

How to make two plots on a different scale

asked 2014-10-12 02:46:38 +0100

Jorge gravatar image

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2014-10-12 12:04:45 +0100

ndomes gravatar image

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)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-10-12 02:46:38 +0100

Seen: 620 times

Last updated: Oct 12 '14