Davide-sd / sympy-plot-backends

An improved plotting module for SymPy
BSD 3-Clause "New" or "Revised" License
42 stars 9 forks source link

quiver in 3d? #38

Closed imakn634 closed 3 months ago

imakn634 commented 4 months ago

I would like to know how to plot a (few) vector(s) in 3d.

We can plot a 2d quiver in SPB:

from sympy import *
from spb import *

p=plot(xlim=(-2,2), ylim=(-2,2), aspect='equal', show=False)
ax=p.ax
ax.quiver([0],[0],[1],[1],
          angles='xy', scale_units='xy', scale=1);

fig1

It is essentially in the same way as in Matplotlib:

import matplotlib.pyplot as plt
ax = plt.figure().add_subplot()
ax.set_aspect('equal')
ax.set_xlim(-2,2)
ax.set_ylim(-2,2)
ax.quiver([0],[0],[1],[1],
          angles='xy', scale_units='xy', scale=1);

fig2

Matplotlib can also plot a 3d quiver:

import matplotlib.pyplot as plt
ax = plt.figure().add_subplot(projection='3d')
ax.set_aspect('equal')
ax.set_xlim(-2,2)
ax.set_ylim(-2,2)
ax.set_zlim(-2,2)
ax.quiver([0],[0],[0], [1],[1],[1]);

fig3

Therefore, I wonder if I can set projection='3d' option in SPB...
Is it possible to plot a (few) vector(s) in 3d using SPB?

Davide-sd commented 4 months ago

For 2D arrows, you can use the graphics function together with arrow_2d. Take a look at these examples.

Currently, arrow_3d is not implemented. Maybe in the future, who knows.

imakn634 commented 4 months ago

Thank you. Our Jupyter server is still spb 2.4.3. I will try the graphics function after upgrading to 3.0.1...

Long time before, you you answered me that once "ax" is set, we can set any detailed options (which are not implemented in spb) in the same way as in Matplotlib.
arrow_2d is no implemented in spb 2.4.3, but we can plot 2d vectors using ax.quiver().
So I had a dream something like

from sympy import *
from spb import *

p=plot3d(xlim=(-2,2), ylim=(-2,2), show=False)
ax=p.ax
ax.quiver([0],[0],[0], [1],[1],[1]);

might work. It does not work for now, but maybe in the future...

Davide-sd commented 3 months ago

I've just released a new version in which I have implemented the arrow_3d function.

I'm closing this issue.