Ask Your Question
1

How do I plot multiple functions in one graph?

asked 3 years ago

ivaralink gravatar image

updated 3 years ago

dsejas gravatar image

What I do:

x, y = SR.var('x, y')
eq1 = 2*x + y == 8
eq2 = 5*x -7*y == 1
implicit_plot([eq1,eq2],(x,-2,5),(y,-2,5))

What I get:

TypeError: 'tuple' object is not callable

What am I doing wrong?

Preview: (hide)

Comments

The best i can find is:

show(implicit_plot(eq1,(x,-2,5),(y,-2,5)) + implicit_plot(eq2,(x,-2,5),(y,-2,5)))

But it sould be possible to do it shorter, should't it?

ivaralink gravatar imageivaralink ( 3 years ago )

Since plot can plot either a function or a list of functions, it is indeed a bit surprising that implicit_plot only accepts one equation, and not a list of equations. But that's how it is at this point!

slelievre gravatar imageslelievre ( 3 years ago )

Strange as it may seem , i checked the documentation and the parameters correspond to the documentation. Strange but correct, there probably is a reason.

ivaralink gravatar imageivaralink ( 3 years ago )

Do you mean this example is from the documentation and it fails? Can you say what page?

slelievre gravatar imageslelievre ( 3 years ago )

Bi, i mean that according to the documentation plot takes a collection of objects and implicit_plot only takes a function. The difference is strange

ivaralink gravatar imageivaralink ( 3 years ago )

1 Answer

Sort by » oldest newest most voted
2

answered 3 years ago

dsejas gravatar image

updated 3 years ago

Hello, @ivaralink! Indeed, the solution you pose in your own comment is correct, albeit not stylistically elegant. Superimposing plots can be achieved by "adding" them. However, doing so in one command is considered a poor programming practice. I would recommend doing the following:

P1 = implicit_plot(eq1, (x,-2,5), (y,-2,5))
P2 = implicit_plot(eq2, (x,-2,5), (y,-2,5))
show(P1 + P2)

Even better, you can use the += composite operator:

P = implicit_plot(eq1, (x,-2,5), (y,-2,5))
P += implicit_plot(eq2, (x,-2,5), (y,-2,5))
P.show()

(Alternatively, this last line can also be show(P).)

I recommend you read the 2D plotting documentation. Also, if you are beginner, I also recommend you read this book by Gregory Bard, which can be downloaded for free..

I hope this helps!

Preview: (hide)
link

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: 3 years ago

Seen: 1,418 times

Last updated: Aug 21 '21