1

I do some image processing and for this purpose I want to visualize my data using mayavi.mlab (I have a distribution of unit vectors in 3D). However, I want to show my data on the surface of a unit sphere. With mlab.axes I got a cartesian coordinate system, what is fine. But I want this coordinate system to be moved to the center of the sphere. How can I do that?

I already have the sphere, a grid on the sphere my data (not shown in the provided code snippet), a colorbar and so on. I also tried to construct a coordinate system by myself using mlab.plot3d and then plotted 3 lines. But of course these lines don't have labels, ticks or arrows at the end.

import numpy as np
from mayavi import mlab

## Create a sphere
r = 1.0
pi = np.pi
cos = np.cos
sin = np.sin
phi, theta = np.mgrid[-0.5*pi:0.5*pi:101j, 0:1*pi:101j]

## Polarcoordinates of the sphere
x = r*sin(phi)*cos(theta)
y = r*sin(phi)*sin(theta)
z = r*cos(phi)

## Basic settings mlab
mlab.figure(1, bgcolor=(1, 1, 1), fgcolor=(0, 0, 0), size=(500, 500))
mlab.clf()

## Plot unit sphere
mlab.mesh(x , y , z, color=(0.9,0.,0.), opacity=0.3)

## My approach for the centered coordinate system
ax=[[0,0.5,1,1.5],[0,0,0,0]]
x_ax_x=ax[0]
x_ax_y=ax[1]
x_ax_z=ax[1]

y_ax_x=ax[1]
y_ax_y=ax[0]
y_ax_z=ax[1]

z_ax_x=ax[1]
z_ax_y=ax[1]
z_ax_z=ax[0]

mlab.plot3d(x_ax_x, x_ax_y, x_ax_z, tube_radius=None, color=(0,0,0))
mlab.plot3d(y_ax_x, y_ax_y, y_ax_z, tube_radius=None, color=(0,0,0))
mlab.plot3d(z_ax_x, z_ax_y, z_ax_z, tube_radius=None, color=(0,0,0))

mlab.show()

Is there an easy way to get a centered coordinate system, or do I have to build it by myself? And if so, how can I add arrows, labels and ticks to the lines?

Thanks in advance

Phtagen

Phtagen
  • 121
  • 10
  • there's not a function in Mayavi for what you request. Someone [here](https://stackoverflow.com/a/24340607/3637404) had a similar problem with axes for a cartesian coordinate system and ended up plotting them themselves – Felipe Lema Jul 02 '19 at 13:09
  • Thank you for your answer and sharing the link... I also managed the axes-plot by myself on a similar way... – Phtagen Jul 16 '19 at 08:14

0 Answers0