pyvista / pyvista-support

[moved] Please head over to the Discussions tab of the PyVista repository
https://github.com/pyvista/pyvista/discussions
60 stars 4 forks source link

orientation of axis widget #288

Closed gokhalen closed 3 years ago

gokhalen commented 3 years ago

Description

I'm a PyVista newbie who is trying to set the orientation of the axes. When I plot using the code below, the X axis is vertical on the screen, and the Y-axis is horizontal. How can I get the X axis to be horizontal and the Y axis to be vertical? I'm using PyVista 0.27.2 installed using conda. I'm running the code inside the Spyder IDE.

Example Code

import numpy as np
import pyvista as pv

# mesh points
vertices = np.array([[0, 0, 0],
                     [1, 0, 0],
                     [1, 1, 0],
                     [0, 1, 0],
                     [2, 0, 0],
                     [3, 1, 0]])

# mesh faces
faces = np.hstack([[4, 0, 1, 2, 3],
                   [4, 1, 4, 5, 2]])    # triangle

surf = pv.PolyData(vertices, faces)
surf.point_arrays['point1'] = np.arange(surf.n_points)
surf.cell_arrays['cell1']   = np.arange(surf.n_cells)

sargs = dict(height=0.25, vertical=True, position_x=0.85, position_y=0.05)

p = pv.Plotter()
p.show_axes()
p.add_mesh(surf,scalars='point1',scalar_bar_args=sargs)
p.camera_position = [0.0,0.0,1.5]
p.show(screenshot='pyvistatest.png')
banesullivan commented 3 years ago

We have a helper method to do that for you: view_xy()

p = pv.Plotter()
p.show_axes()
p.add_mesh(surf,scalars='point1',scalar_bar_args=sargs)
p.view_xy()
p.show()

download

banesullivan commented 3 years ago

camera_position set's the world coordinates of the camera. If trying to manually position the camera angle, it is much easier to do so with the viewup vector using set_viewup()

gokhalen commented 3 years ago

Thanks, that worked.