# How do I plot multiple functions in one graph?

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?

edit retag close merge delete

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?

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!

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

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

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

Sort by » oldest newest most voted

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 hope this helps!

more