# How to save combinations of plots?

I can ceate several plots like this

a = plot(f1, (x,-1,2))
b = plot(f2, (x,-1,2))
c = plot(f3, (x,-1,2))


and merge them with

show(a+b+c)


How can I save the resulting image?

show(a+b+c).save('pic.pdf')


does not work.

edit retag close merge delete

Sort by » oldest newest most voted

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')

more

You can also combine the graphs with just one plot command:

 pic = plot([f1,f2,f3], (x,-1,2), color=["red","green", "blue"])