# Examples from pyvista.Plotter.add_scalar_bar
# ============================================

# Add a custom interactive scalar bar that is horizontal, has an
# outline, and has a custom formatting.
import pyvista as pv
sphere = pv.Sphere()
sphere['Data'] = sphere.points[:, 2]
pl = pv.Plotter()
_ = pl.add_mesh(sphere, show_scalar_bar=False)
_ = pl.add_scalar_bar(
    'Data',
    interactive=True,
    vertical=False,
    title_font_size=35,
    label_font_size=30,
    outline=True,
    fmt='%10.5f',
)
pl.show()

# Add a custom scalar bar without (or before) plotting data using the
# `cmap` and `clim` parameters:
import pyvista as pv
pl = pv.Plotter()
_ = pl.add_scalar_bar('Height', cmap='viridis', clim=(-2, 2))
pl.show()

# Stack three scalar bars with titles of different lengths.  They are
# spaced so that nothing overlaps.
import pyvista as pv
sphere = pv.Sphere()
sphere['Data'] = sphere.points[:, 2]
titles = ['A bit long', 'Short', 'Super duper long']
pl = pv.Plotter()
pl.theme.colorbar_vertical.position_x = 0.75
_ = pl.add_mesh(sphere, show_scalar_bar=False)
for title in titles:
    _ = pl.add_scalar_bar(
        title,
        vertical=True,
        title_font_size=30,
        label_font_size=30,
        mapper=pl.mapper,
    )
pl.show()

# Turn the titles alongside the bars to stack them closer together.
pl = pv.Plotter()
pl.theme.colorbar_vertical.position_x = 0.75
_ = pl.add_mesh(sphere, show_scalar_bar=False)
for title in titles:
    _ = pl.add_scalar_bar(
        title,
        vertical=True,
        rotate_title=True,
        title_font_size=30,
        label_font_size=30,
        mapper=pl.mapper,
    )
pl.show()

# Space the bars evenly instead, whatever their titles measure.
pl = pv.Plotter()
pl.theme.colorbar_vertical.position_x = 0.75
_ = pl.add_mesh(sphere, show_scalar_bar=False)
for title in titles:
    _ = pl.add_scalar_bar(
        title,
        vertical=True,
        stacking_gap=0.2,
        title_font_size=30,
        label_font_size=30,
        mapper=pl.mapper,
    )
pl.show()

# A box drawn around a bar grows to hold the title and the tick labels, as long
# as the bar was not given a size of its own.
pl = pv.Plotter()
_ = pl.add_mesh(sphere, show_scalar_bar=False)
_ = pl.add_scalar_bar(
    'Elevation (m)',
    vertical=True,
    outline=True,
    title_font_size=30,
    label_font_size=30,
    mapper=pl.mapper,
)
pl.show()

# A horizontal bar's ramp and tick labels are laid out inside its box, and the
# box grows to hold the padding the title is given.
pl = pv.Plotter()
_ = pl.add_mesh(sphere, show_scalar_bar=False)
_ = pl.add_scalar_bar(
    'Elevation (m)',
    vertical=False,
    outline=True,
    title_font_size=30,
    label_font_size=30,
    mapper=pl.mapper,
)
pl.show()

# ----------------------------------------------------------------------
# Generated by sphinx-examples-as-code https://github.com/pyvista/sphinx-examples-as-code
