Ask Your Question
0

How to save combinations of plots?

asked 2019-04-01 00:28:40 +0200

stockh0lm gravatar image

updated 2019-04-01 01:30:52 +0200

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

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-04-01 02:32:44 +0200

dazedANDconfused gravatar image

updated 2019-04-01 14:55:07 +0200

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

Comments

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

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

Juanjo gravatar imageJuanjo ( 2019-04-01 11:07:44 +0200 )edit

Your Answer

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

Add Answer

Question Tools

2 followers

Stats

Asked: 2019-04-01 00:28:40 +0200

Seen: 88 times

Last updated: Apr 01 '19