Python:如何在不需要linspace / meshgrid的情况下制作(3d)函数图?

时间:2023-01-27 23:46:48

Question:

In WolframAlpha, I can get a plot for "z = x^2 - y^2" directly from that string. How would one make plots like the above from a string in python?

在WolframAlpha中,我可以直接从该字符串获得“z = x ^ 2 - y ^ 2”的图。如何从python中的字符串中创建如上图?

A few things I already know about:

  • You can do linspace or meshgrid, compute the function at each point, and then pass those values to either matplotlib or plotly. Plotly makes beautiful plots in this case, and this is what I'm using right now, but it's definitely still a hassle.

    你可以做linspace或meshgrid,计算每个点的函数,然后将这些值传递给matplotlib或plotly。在这种情况下Plotly制作漂亮的情节,这就是我现在正在使用的,但它绝对是一个麻烦。

  • It's possible to do plotting in Sympy, but that library is a little heavy-handed in its own way, and the documentation is a little sparse.

    可以在Sympy中进行绘图,但是这个库以自己的方式有点笨拙,而且文档有点稀疏。

What would make a great answer:

  • A library I haven't heard of or been able to find which provides easy, elegant plotting of functions without needing to do the linspace myself.

    一个我没有听说过或者能够找到的库,它提供了简单,优雅的函数绘图,而不需要自己做linspace。

  • A thorough explanation of why the available tools I listed above are the best you can do, and perhaps some tutorials you like for getting a better grasp of these techniques.

    彻底解释为什么我上面列出的可用工具是你能做的最好的,也许你喜欢的一些教程可以更好地掌握这些技巧。

Updates:

1 个解决方案

#1


1  

sympy has a plotting module, pretty much just the example code

sympy有一个绘图模块,几乎就是示例代码

from sympy import symbols
from sympy.plotting import plot3d
x, y = symbols('x y')

plot3d((x**2 - y**2))  

Python:如何在不需要linspace / meshgrid的情况下制作(3d)函数图?

#1


1  

sympy has a plotting module, pretty much just the example code

sympy有一个绘图模块,几乎就是示例代码

from sympy import symbols
from sympy.plotting import plot3d
x, y = symbols('x y')

plot3d((x**2 - y**2))  

Python:如何在不需要linspace / meshgrid的情况下制作(3d)函数图?