Skip to content

Commit

Permalink
Add unconstrained_font_size to add_scalar_bar (#5317)
Browse files Browse the repository at this point in the history
* Add `unconstrained_font_size` to `add_scalar_bar`

* Apply suggestions from code review

* Apply suggestions from code review

* Add versionadded

* Add test

* Apply suggestions from code review
  • Loading branch information
tkoyama010 committed Dec 12, 2023
1 parent 52a2506 commit a150a95
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pyvista/plotting/scalar_bars.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def add_scalar_bar(
fill=False,
render=False,
theme=None,
unconstrained_font_size=False,
):
"""Create scalar bar using the ranges as set by the last input mesh.
Expand Down Expand Up @@ -304,6 +305,14 @@ def add_scalar_bar(
``Plotter``, will use the plotter theme. Setting to
``None`` will use the global theme.
unconstrained_font_size : bool, default: False
Whether the font size of title and labels is unconstrained.
When it is constrained, the size of the scalar bar will constrain the font size.
When it is not, the size of the font will always be respected.
Using custom labels will force this to be ``True``.
.. versionadded:: 0.44.0
Returns
-------
vtk.vtkScalarBarActor
Expand Down Expand Up @@ -552,6 +561,9 @@ def add_scalar_bar(
else:
scalar_bar.SetDrawFrame(False)

if unconstrained_font_size:
scalar_bar.SetUnconstrainedFontSize(True)

# finally, add to the actor and return the scalar bar
self._plotter.add_actor(scalar_bar, reset_camera=False, pickable=False, render=render)

Expand Down
8 changes: 8 additions & 0 deletions tests/plotting/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,14 @@ def test_plot_invalid_add_scalar_bar():
plotter.add_scalar_bar()


def test_add_scalar_bar_with_unconstrained_font_size(sphere):
sphere['test_scalars'] = sphere.points[:, 2]
plotter = pv.Plotter()
plotter.add_mesh(sphere)
actor = plotter.add_scalar_bar(unconstrained_font_size=True)
assert actor.GetUnconstrainedFontSize()


def test_plot_list():
sphere_a = pv.Sphere(0.5)
sphere_b = pv.Sphere(1.0)
Expand Down

0 comments on commit a150a95

Please sign in to comment.