def create_ruler_in(x1, y1, x2, y2,title="",tick_dis=10):
ruler = pv.plotting._vtk.vtkAxisActor2D()
ruler.GetPositionCoordinate().SetCoordinateSystemToDisplay()
ruler.GetPosition2Coordinate().SetCoordinateSystemToDisplay()
ruler.GetPositionCoordinate().SetReferenceCoordinate(None)
ruler.GetPositionCoordinate().SetValue(x1, y1)
ruler.GetPosition2Coordinate().SetValue(x2, y2)
distance = np.linalg.norm(np.asarray([x1, y1]) - np.asarray([x2, y2]))
ruler.SetRange(0, distance)
if title != "":
ruler.SetTitle(title)
label_color = pv.plotting.Color('red')
ruler.SetFontFactor(0.6)
ruler.GetTitleTextProperty().SetColor(label_color.float_rgb)
ruler.GetTitleTextProperty().SetFontSize(12)
ruler.SetTitlePosition(0.5)
ruler.UseFontSizeFromPropertyOn()
ruler.GetProperty().SetColor(*tick_color.int_rgb)
ruler.SetLabelVisibility(False)
ruler.SetTickVisibility(True)
plotter.add_actor(ruler, reset_camera=False, pickable=False)
The above is function to draw lines of a cross-hair on pyvista 3d using vtkAxisActor2D(). The ticks are only on one side of the ruler can we make it to both sides And can we dynamically give distance between ticks
Image of what i am getting here. I need the ticks on both side of the line and also change the distance between the text.
For ticks on both side a workaround would be to draw the line again from other end
create_ruler_in(x1, y1, x2, y2,title="",tick_dis=10)
create_ruler_in(x2, y2, x1, y1,title="",tick_dis=10)
And for distance set
ruler.SetRulerMode(True)
ruler.SetRulerDistance(#distance you need)