How to scale axes independently in pyvista?

447 Views Asked by At

Suppose I have x, y, z and x2, y2, z2 arrays. I am plotting them as 2 different 3d splines in pyvista.

import numpy as np
import pyvista as pv

network = pv.MultiBlock()

points_1 = np.column_stack((x, y, z))
spline_1 = pv.Spline(points_1, 500).tube(radius=0.1)

points_2 = np.column_stack((x2, y2, z2))
spline_2 = pv.Spline(points_2, 500).tube(radius=0.1)

network.append(spline_1)
network.append(spline_2)

p = pv.Plotter()
labels = dict(zlabel='l1', xlabel='l2', ylabel='l2')
p.show_grid(**labels)
p.add_axes(**labels)
p.add_mesh(spline_1, color="red", line_width=3)
p.add_mesh(spline_2, color="blue", line_width=3)

The problem of this plot is that one axis is too compressed: y axis values are around 300 whereas x axis range from 0 to 20. It seems the plot uses the same scale for all axis. Furthermore, x and y are different quantity so I don't want to compare them.

Matplotlib for example automatically scales the axes and to use the same scale on, for example, y and x axes you do ax.set_aspect("equalxy").

In this case axes are already scaled and I want to make one use a different size. How can I do that?

1

There are 1 best solutions below

0
Bane Sullivan On

PyVista plots in physical cartesion space, so you'll need to set the scale on the scene with pl.set_scale() See docs: https://docs.pyvista.org/version/stable/api/plotting/_autosummary/pyvista.Plotter.set_scale.html#pyvista.Plotter.set_scale