Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Try this:

f1=x
f2=cos(x)
f3=x^2
a = plot(f1, (x,-1,2))
b = plot(f2, (x,-1,2))
c = plot(f3, (x,-1,2))
pic = a+b+c
pic.save('pic.pdf')

Press on the link pic.pdf to see it and download it.

Try this:

f1=x
f2=cos(x)
f3=x^2
a = plot(f1, (x,-1,2))
b = plot(f2, (x,-1,2))
c = plot(f3, (x,-1,2))
pic = a+b+c
pic.save('pic.pdf')

Press on the link pic.pdf to see it and download it.it. Note, with multiple plots you might want to color them. This can be done, for example, with b = plot(f2, (x,-1,2),color='red')

Basically you want to save the picture, not show it. combining show and save is the problem. Try this:

f1=x
f2=cos(x)
f3=x^2
a = plot(f1, (x,-1,2))
b = plot(f2, (x,-1,2))
c = plot(f3, (x,-1,2))
pic = a+b+c
pic.save('pic.pdf')

Press on the link pic.pdf to see it and download it. Note, with multiple plots you might want to color them. This can be done, for example, with b = plot(f2, (x,-1,2),color='red')

Basically you want to save the picture, not show it. combining show and save is the problem. Try this:

f1=x
f2=cos(x)
f3=x^2
a = plot(f1, (x,-1,2))
b = plot(f2, (x,-1,2))
c = plot(f3, (x,-1,2))
pic = a+b+c
pic.save('pic.pdf')

Press on the link pic.pdf to see it and download it. Note, with multiple plots you might want to color them. This can be done, for example, with b = plot(f2, (x,-1,2),color='red')(x,-1,2),color='red'). If you want to show as well insert the line pic.show() right after pic is defined.

Basically you want to save the picture, not show it. combining show and save is the problem. Try this:

f1=x
f2=cos(x)
f3=x^2
a = plot(f1, (x,-1,2))
b = plot(f2, (x,-1,2))
c = plot(f3, (x,-1,2))
pic = a+b+c
pic.save('pic.pdf')

Press on the link pic.pdf to see it and download it. Note, with multiple plots you might want to color them. This can be done, for example, with b = plot(f2, (x,-1,2),color='red'). If you want to show as well insert the line pic.show() right after pic is defined.

EDIT: As Juanjo comments below, you can combine the 3 plots into 1. If you stack the functions together on one line using ; you can compress the code even more:

f1=x; f2=cos(x); f3=x^2
pic = plot([f1,f2,f3], (x,-1,2), color=["red","green", "blue"]) 
pic.save('pic.pdf')