简体   繁体   中英

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))

使用 Sympy 绘图

Using matplotlib it is straight forward to add a grid :

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

使用 matplotlib 的网格

How can I do this with Sympy?

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

Please add this.

import seaborn as sns
sns.set()
sns.set_style("whitegrid", {'grid.linestyle': '--'})

You can get fig like this: 在此处输入图片说明

import sympy
from sympy import sin
from sympy.abc import x
from math import pi
import seaborn as sns
sns.set()
sns.set_style("whitegrid", {'grid.linestyle': '--'})

sympy.plot(sin(x),xlim=(0,2*pi))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM