如何在Sympy绘图中显示网格

4

我想使用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

使用Matplotlib添加网格很简单:
import matplotlib.pylab as plt
plt.grid(True)
plt.show()

Grid using matplotlib

我该如何使用Sympy实现这个?


有人知道这是否是使用Sympy实现的吗? - imranal
2个回答

4

由于SymPy在内部使用matplotlib,如果您有可用的话,您可以使用以下命令:

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

您可以使用 sympy.plot() 函数来设置样式。

要打印所有可用的样式,请使用:

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

这里是有关Matplotlib样式的链接


2
请添加此内容。
import seaborn as sns
sns.set()
sns.set_style("whitegrid", {'grid.linestyle': '--'})

您可以这样获取fig:enter image description here
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))

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接