Cómo hacer un gráfico de dispersión 3D en Python?
Actualmente tengo una matriz nx3. Quiero trazar las tres columnas como tres ejes. ¿Cómo puedo hacer eso?
He buscado en Google y la gente sugirió usar Matlab, pero realmente estoy teniendo dificultades para entenderlo. También necesito que sea un gráfico de dispersión.
Alguien Puede enseñarme?
4 answers
Puede usar matplotlib para esto. matplotlib tiene un módulo mplot3d que hará exactamente lo que quieras.
from matplotlib import pyplot
from mpl_toolkits.mplot3d import Axes3D
import random
fig = pyplot.figure()
ax = Axes3D(fig)
sequence_containing_x_vals = list(range(0, 100))
sequence_containing_y_vals = list(range(0, 100))
sequence_containing_z_vals = list(range(0, 100))
random.shuffle(sequence_containing_x_vals)
random.shuffle(sequence_containing_y_vals)
random.shuffle(sequence_containing_z_vals)
ax.scatter(sequence_containing_x_vals, sequence_containing_y_vals, sequence_containing_z_vals)
pyplot.show()
El código anterior genera una figura como:
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-06-20 04:26:12
¡Usa asíntota en su lugar!
Esto es lo que puede parecer:
Http://asymptote.sourceforge.net/gallery/3D%20graphs/helix.pdf
Este es el código: http://asymptote.sourceforge.net/gallery/3D%20graphs/helix.asy
La asíntota también se puede leer en archivos de datos.
Y la galería completa: http://asymptote.sourceforge.net/gallery /
Para usar la asíntota desde dentro Python:
Http://www.tex.ac.uk/tex-archive/graphics/asymptote/base/asymptote.py
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-12-31 15:56:25
Use el siguiente código que funcionó para mí:
# Create the figure
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Generate the values
x_vals = X_iso[:, 0:1]
y_vals = X_iso[:, 1:2]
z_vals = X_iso[:, 2:3]
# Plot the values
ax.scatter(x_vals, y_vals, z_vals, c = 'b', marker='o')
ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
ax.set_zlabel('Z-axis')
plt.show()
Mientras que X_iso es mi matriz 3-D y para X_vals, Y_vals, Z_vals copié/usé 1 columna/eje de esa matriz y asigné a esas variables/matrices respectivamente.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-11-27 08:35:54
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-12-31 16:35:38