user1968963
user1968963

Reputation: 2501

ipython qtconsole: drawing multiple functions inside one plot

In ipython-qtconsole, I can easily create a simple plot:

ipython qtconsole --pylab=inline

x = linspace(0, 2*pi, 1000)
plot(x, sin(x))

enter image description here

Is there a way to specify multiple functions to be drawn inside the same plot ? I have tried the following, but neither works:

plot(x, sin(x), cos(x))
plot(x, [sin(x), cos(x)])
plot(x, {sin(x), cos(x)})

Upvotes: 0

Views: 333

Answers (2)

Rutger Kassies
Rutger Kassies

Reputation: 64443

You can define a figure and axes, draw all the plots and then display the figure. Creating them will also display the empty figure once, i dont know if that can be supressed.

So:

x = linspace(0, 2*pi, 1000)

fig, ax = plt.subplots()

ax.plot(x, sin(x))    
ax.plot(x, cos(x))

display(fig)

That would show all functions in the same axes.

Upvotes: 1

Martin Vegter
Martin Vegter

Reputation: 527

You can write multiple plot commands on the same line, separated with a comma:

x = linspace(0, 2*pi, 1000)
plot(x, sin(x)), plot(x, cos(x))

enter image description here

Upvotes: 0

Related Questions