pyvista / pyvista

3D plotting and mesh analysis through a streamlined interface for the Visualization Toolkit (VTK)
https://docs.pyvista.org
MIT License
2.59k stars 478 forks source link

number_labels in add_ruler not working as expected; similar for show_bounds #6252

Open heril96 opened 2 months ago

heril96 commented 2 months ago

Describe the bug, what's wrong, and what you expected.

I found a bug!

My application required adding multiple ticks and the data set where i am using pyvista is multiblock data set with x axis range from -1.4m to 1.4. I am adding two rulers one in +ve x dirn and another in -ve x dirn, the issue is I can only add total 5 labels from 0 to 1.4m even if i want to add 20. Moreover when i use ruler in negative x-dirn which is 0 to -1.4m the ticks are above the x axis and total label number is fixed to 5. Attached image!

Below is different example pasted for which increasing the number of labels is not changing the number of labels (but the numbers do change, please try) but reducing the number_labels reduces the ticks. If i want to produce 15 ticks it is not possible here but produce 3 is possible in below example.

Steps to reproduce the bug.

import pyvista as pv
data = [
    pv.Sphere(center=(2, 0, 0)),
    pv.Cube(center=(0, 2, 0)),
    pv.Cone(),
]
blocks = pv.MultiBlock(data)

#blocks.center=[2,2,2]
translation_vector = (2, 1, 2)
for i in range(len(blocks)):
    blocks[i].translate(translation_vector, inplace=True)
print(blocks.center) 
plotter = pv.Plotter()
plotter.add_mesh(blocks, smooth_shading=True)
plotter.show_bounds(n_xlabels=10,n_ylabels=20) 
plotter.view_xy()
plotter.show()

System Information

--------------------------------------------------------------------------------
  Date: Thu Jun 13 10:28:02 2024 India Standard Time

                  OS : Windows (10 10.0.19045 SP0 Multiprocessor Free)
              CPU(s) : 16
             Machine : AMD64
        Architecture : 64bit
                 RAM : 31.7 GiB
         Environment : IPython
         GPU Details : error
    MathText Support : False

  Python 3.11.9 | packaged by Anaconda, Inc. | (main, Apr 19 2024, 16:40:41)
  [MSC v.1916 64 bit (AMD64)]

             pyvista : 0.43.8
                 vtk : 9.3.0
               numpy : 1.26.4
          matplotlib : 3.8.4
              scooby : 0.10.0
               pooch : 1.8.1
              pillow : 10.3.0
             imageio : 2.33.1
               PyQt5 : 5.15.10
             IPython : 8.20.0
            colorcet : 3.1.0
             cmocean : 4.0.3
          ipywidgets : 8.1.2
               scipy : 1.13.0
                tqdm : 4.66.4
              meshio : 5.3.5
          jupyterlab : 4.0.11
               trame : 3.6.0
        trame_client : 3.0.3
        trame_server : 3.0.0
           trame_vtk : 2.8.8
       trame_vuetify : 2.5.0
jupyter_server_proxy : 4.1.2
        nest_asyncio : 1.6.0

  Intel(R) oneAPI Math Kernel Library Version 2023.1-Product Build 20230303
  for Intel(R) 64 architecture applications
---------------------------------------------------------------------------------

Screenshots

Screenshot 2024-06-13 103734

MatthewFlamm commented 2 months ago

To clarify, this problem is not in add_ruler, but show_bounds?

heril96 commented 2 months ago

No, it is there in add_ruler for sure.

Show bound is also have similar strange behaviour but it is not required now.

MatthewFlamm commented 2 months ago

Can you add a second issue for the direction of the ruler with an example with code, if it continues to be an issue? I highly suspect it is due to this line in the documentation of add_ruler.

The title and labels are placed to the right of ruler moving from pointa to pointb. Use flip_range to flip the 0 location, if needed.

Note that you can use different choices of pointa and pointb and flip_range to get the desired number ordering and side for the labels.

https://docs.pyvista.org/version/stable/api/plotting/_autosummary/pyvista.Renderer.add_ruler.html#pyvista-renderer-add-ruler

heril96 commented 2 months ago

Can you add a second issue for the direction of the ruler with an example with code, if it continues to be an issue? I highly suspect it is due to this line in the documentation of add_ruler.

The title and labels are placed to the right of ruler moving from pointa to pointb. Use flip_range to flip the 0 location, if needed.

Note that you can use different choices of pointa and pointb and flip_range to get the desired number ordering and side for the labels.

https://docs.pyvista.org/version/stable/api/plotting/_autosummary/pyvista.Renderer.add_ruler.html#pyvista-renderer-add-ruler

previously when i was trying to show ruler with the command "p.add_ruler([0,0,0],[-0.7,0,0],number_labels=5, font_size_factor=0.4) " Then it was showing the labels above axis as shown in the image attached before but now when i tried it with command as per your suggestion it looks normal. I think we have to handle this differently to show it correct way. The command i used now is as below "p.add_ruler([-0.70,0,0],[0,0,0],flip_range=True,number_labels=5,font_size_factor=0.4)"

image