我想使用 Sympy 显示带有绘图的网格:
import sympy
from sympy import sin
from sympy.abc import x
from math import pi
sympy.plot(sin(x),xlim=(0,2*pi))
使用 matplotlib 可以直接添加网格:
import matplotlib.pylab as plt
plt.grid(True)
plt.show()
如何使用 Sympy 执行此操作?
由于 SymPy 在底层使用 matplotlib(如果有的话), 你可以使用:
from matplotlib import style
style.use('ggplot')
这将为你的 sympy.plot() 设计风格
要打印所有可用样式,请使用:
import matplotlib as plt
print(plt.style.available)
这里有关于 matplotlib 的样式的链接
请添加此内容。
import seaborn as sns
sns.set()
sns.set_style("whitegrid", {'grid.linestyle': '--'})
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))
我使用了与@mauricio777相同的解决方案。我发现显示/可视化样式的网站非常有用: https://matplotlib.org/stable/gallery/style_sheets/style_sheets_reference.html
我个人更喜欢使用:
from matplotlib import style
style.use('seaborn-v0_8-whitegrid')