7

Trying to do some plotting in SymPy -

As per this video I have written :

from sympy.plotting import plot, plot_parametric

e = sin(2*sin(x**3))
plot(e, (x, 0, 5));

But after evaling that cell I don't get any output? There isn't an error or anything, it just doesn't display anything.

Another test :

from sympy import *
from sympy.plotting import plot, plot_parametric
import math
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt


expr = x**2 + sqrt(3)*x - Rational(1, 3)
lf = lambdify(x, expr)

fig = plt.figure()
axes = fig.add_subplot(111)

x_vals = np.linspace(-5., 5.)
y_vals = lf(x_vals)

axes.grid()
axes.plot(x_vals, y_vals)

plt.show();

So Im not sure what I'm doing wrong here, I'm not getting any errors though?

If the virtual environment content is of any interest here's a tree of that : venv

I'm running this on Linux Ubuntu. The virtual environment that it's running in can be seen in the above paste link

2 Answers 2

7

You need to use the magic functions, more specifically the ones for matplotlib:

%matplotlib qt # displays a pop-up of the plot
%matplotlib inline # keeps it within the notebook

Runnable example using Python 3.4 Nov '15:

from sympy import *
from sympy.plotting import plot, plot_parametric
import math
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

%matplotlib inline

expr = x**2 + sqrt(3)*x - Rational(1, 3)
lf = lambdify(x, expr)

fig = plt.figure()
axes = fig.add_subplot(111)

x_vals = np.linspace(-5., 5.)
y_vals = lf(x_vals)

axes.grid()
axes.plot(x_vals, y_vals)
Sign up to request clarification or add additional context in comments.

1 Comment

this is correct thanks, I didn't notice this on the guide that I was following but this now works
4

To get plots to show inline in the IPython notebook, you need to enable matplotlib's inline backend. You can do this by running

%matplotlib inline

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.