Plotting circles in different planes

Asked

Viewed 228 times

-1

I need to plot circles in the plans Zy and zx, but I only get in the plane xy, because when changing the variables x, y and z, forgive the shape of a heart. How can I fix this?

import numpy as np
from matplotlib import pyplot as plt
import mpl_toolkits.mplot3d.axes3d

theta = np.linspace(0, 2.*np.pi, 100)
phi = np.linspace(0, 2*np.pi, 100)
theta, phi = np.meshgrid(theta, phi)
c, a = 1, 0.05
x = (c + a*np.cos(theta)) * np.cos(phi)
y = (c + a*np.cos(theta)) * np.sin(phi)
z = a * np.sin(theta)

fig = plt.figure()
ax1 = fig.add_subplot(111, projection='3d')
ax1.set_zlim(-10,10)
ax1.plot_surface(x, y, z, color='b', edgecolors='b')
ax1.view_init(36, 26)

plt.show()

1 answer

0


You must reset the coordinate of the axis that does not want the circle to appear. For example, if you want to plot the circle on the Zy plane, then

ax1.plot_surface(xzero, y, z, color='b', edgecolors='b')

where xzero is a vector of zeros ([0,0,0,.]) of the same dimension of y and z.

The same thing you do for other plans.

  • It worked, thank you! now I just need to be able to plot in the coordinate I determine :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.