How to display a graph in ipython notebook How to display a graph in ipython notebook python-3.x python-3.x

How to display a graph in ipython notebook


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_parametricimport mathimport numpy as npimport pandas as pdimport matplotlib.pyplot as plt%matplotlib inlineexpr = 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)


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