Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

user27182
Copy link
Contributor

Overview

Originally mentioned here #7788 (comment)
This PR makes it obvious that we're dealing with an object with three attributes

@pyvista-bot pyvista-bot added the enhancement Changes that enhance the library label Aug 7, 2025
MatthewFlamm
MatthewFlamm previously approved these changes Aug 7, 2025
@MatthewFlamm MatthewFlamm dismissed their stale review August 7, 2025 20:15

mistakenly approved wrong PR

@MatthewFlamm
Copy link
Contributor

Does this have a knock on effect for the way that return_cpos=True from Plotter.show is sometimes used? For example, a common use case, at least for me is to use return_cpos=True and then copy and paste the value into my code to use as the starting point. I think this change would remove the ability of quick copy-paste?

Copy link

codecov bot commented Aug 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.40%. Comparing base (91f044c) to head (54e57bb).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7794   +/-   ##
=======================================
  Coverage   96.40%   96.40%           
=======================================
  Files         150      150           
  Lines       32656    32658    +2     
  Branches     4114     4114           
=======================================
+ Hits        31482    31485    +3     
+ Misses        570      569    -1     
  Partials      604      604           

@user27182
Copy link
Contributor Author

user27182 commented Aug 7, 2025

Does this have a knock on effect for the way that return_cpos=True from Plotter.show is sometimes used? For example, a common use case, at least for me is to use return_cpos=True and then copy and paste the value into my code to use as the starting point. I think this change would remove the ability of quick copy-paste?

Yes you're right, this would change that. You should still be able to copy/paste it as-is and use it, since the repr should be useable to init a new CameraPosition object but will need to prepend pv.

We could keep the old behavior with __str__. Using print(cpos) will call __str__, so you can keep the old representation that way.

@pyvista-bot
Copy link
Contributor

pyvista-bot commented Aug 7, 2025

@pyvista-bot pyvista-bot temporarily deployed to pull request August 7, 2025 23:17 Inactive
@user27182 user27182 marked this pull request as ready for review August 8, 2025 06:55
@user27182
Copy link
Contributor Author

Both str and repr are implemented now. The output is consistent with what NumPy does in the sense that array() is included in the repr, but not str output

NDArray:

repr(np.array((1,)))  # 'array([1])'
str(np.array((1,)))  # '[1]'

CameraPosition

# repr
CameraPosition(position=(0.3914, 0.4542, 0.767),
               focal_point=(0.0243, 0.0336, -0.0222),
               viewup=(-0.2148, 0.8998, -0.3796))

# str
[(0.3914, 0.4542, 0.767),
 (0.0243, 0.0336, -0.0222),
 (-0.2148, 0.8998, -0.3796)]

@MatthewFlamm
Copy link
Contributor

I'm +0.2 in favor of this (out of -1 to +1). It is now easier to know what the numbers refer to. One hesitation is that, I assume that, there are a decent number of people who are using environments that show the repr, and that they are using return_cpos to find the final camera position. For example ipython and our own documentation building. One way to soften this blow would be to support this with better documentation. An example is that current show has this in the example. There are likely more of this throughout the documentation.

>>> pl.show(return_cpos=True) # doctest:+SKIP
[(2.223005211686484, -0.3126909484828709, 2.4686209867735065),
(0.0, 0.0, 0.0),
(-0.6839951597283509, -0.47207319712073137, 0.5561452310578585)]

@user27182
Copy link
Contributor Author

user27182 commented Aug 8, 2025

That's a good find, I wonder why that doctest is skipped.

Will do a search for cpos and try to update those examples. We can show both use cases, and maybe use print instead of str in the docs as that may also be more intuitive.

Users can still copy/paste and reuse the output as new input for a cpos keyword, so that functionality isn't really lost. And now if they need to make minor tweaks to CameraPosition.position, it is immediately obvious to users that (1) camera position is more than just a position vector, and (2) it's clear which of the three vectors needs to be changed.

@user27182
Copy link
Contributor Author

That's a good find, I wonder why that doctest is skipped.

It's skipped because it raises a RuntimeError otherwise:
https://github.com/pyvista/pyvista/actions/runs/16918236508/job/47937498711#step:10:2145

RuntimeError: This plotter has been closed and cannot be shown. [docutils]

@pyvista-bot pyvista-bot temporarily deployed to pull request August 12, 2025 23:04 Inactive
@user27182
Copy link
Contributor Author

One hesitation is that, I assume that, there are a decent number of people who are using environments that show the repr, and that they are using return_cpos to find the final camera position. For example ipython and our own documentation building. One way to soften this blow would be to support this with better documentation. An example is that current show has this in the example. There are likely more of this throughout the documentation.

CameraPosition is now used explicitly in all examples to set cpos instead of a list of tuples. @MatthewFlamm does this address your concerns?

@tkoyama010 tkoyama010 added the breaking-change Changes that break backwards compatibility, especially changed default parameters. label Aug 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Changes that break backwards compatibility, especially changed default parameters. enhancement Changes that enhance the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants