Ruler and scaling #6090
-
First check
Commit to Help
Sample Code What is the problem, question, or error?Write a short description telling me what you are doing, what you expect to happen, and what is currently happening. x_ratio = 0.03
offset = 0.01
p = pv.Plotter(off_screen=True,notebook=False)
pointa = [0.0, 0.0, 0.0]
pointb = [15.0, 0.0, 0.0]
pointc = [15.0, 0.1, 0.0]
rec = pv.Rectangle([pointa, pointb, pointc])
p.add_mesh(rec)
p.add_ruler(
pointa=[rec.bounds[0]*x_ratio - offset, rec.bounds[3], 0.0],
pointb=[rec.bounds[0]*x_ratio - offset, rec.bounds[4], 0.0],
flip_range=True,
title="Y",
)
p.add_ruler(
pointa=[rec.bounds[0]*x_ratio, rec.bounds[4] - offset, 0.0],
pointb=[rec.bounds[1]*x_ratio, rec.bounds[4] - offset, 0.0],
title=f"X (*{x_ratio})"
)
p.set_scale(xscale=x_ratio)
p.view_xy()
p.show(screenshot="example.png") DescriptionHi, I have a mesh with a strong aspect ratio. x = [0,15], y = [0;0,1] I can scale down the mesh, DataSet.scale(x_ratio=0.03) or using Plotter.set_scale(xscale=0.03) However when I add the ruler to the plotter with : plotter.add_ruler, I cannot get the original value on ticks. Is it possible to get a scaled plotter with the ruler labels values of the original mesh ? As you can see on this picture, my x ruler goes from 0 to 0.5 instead of 0 to 15. System Information--------------------------------------------------------------------------------
OS : Windows
CPU(s) : 12
Machine : AMD64
Architecture : 64bit
RAM : 15.6 GiB
Environment : Python
GPU Vendor : Intel
GPU Renderer : Intel(R) Iris(R) Xe Graphics
GPU Version : 4.5.0 - Build 31.0.101.4953
MathText Support : False
Python 3.10.0 (tags/v3.10.0:b494f59, Oct 4 2021, 19:00:18) [MSC v.1929 64
bit (AMD64)]
pyvista : 0.43.5
vtk : 9.3.0
numpy : 1.26.3
matplotlib : 3.8.2
scooby : 0.9.2
pooch : 1.8.0
pillow : 10.2.0
imageio : 2.34.0
PyQt5 : 5.15.10
IPython : 8.20.0
colorcet : 3.1.0
cmocean : 4.0.3
ipywidgets : 8.1.2
tqdm : 4.66.1
meshio : 5.3.5
jupyterlab : 4.0.11
trame : 3.6.0
trame_client : 3.0.2
trame_server : 3.0.0
trame_vtk : 2.8.6
trame_vuetify : 2.4.3
jupyter_server_proxy : 4.1.2
nest_asyncio : 1.6.0
-------------------------------------------------------------------------------- Screenshots |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
It looks like ruler = p.add_ruler(...)
a, b = ruler.GetRange() # Either (0, distance) or (distance, 0)
ruler.SetRange(a / x_ratio, b / x_ratio) |
Beta Was this translation helpful? Give feedback.
It looks like
add_ruler
sets the range of the ruler to the distance betweenpointa
andpointb
. Here's a quick kludge that I think does what you're looking for