Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display grid on plot in sympy

I would like to display a grid with a plot using Sympy:

import sympy
from sympy import sin
from sympy.abc import x
from math import pi
sympy.plot(sin(x),xlim=(0,2*pi))

Plot using Sympy

Using matplotlib it is straight forward to add a grid :

import matplotlib.pylab as plt
plt.grid(True)
plt.show()

Grid using matplotlib

How can I do this with Sympy?

like image 674
imranal Avatar asked Oct 27 '25 20:10

imranal


1 Answers

Since SymPy uses matplotlib under the hood if you have it available, you can use:

from matplotlib import style
style.use('ggplot')

And that will style your sympy.plot()

To print all available styles, use:

import matplotlib as plt
print(plt.style.available)

Here's a link about style for matplotlib

like image 97
mauricio777 Avatar answered Oct 30 '25 12:10

mauricio777