# Examples from pyvista.Plotter.add_legend
# ========================================

# Create a legend by labeling the meshes when using `add_mesh`
import pyvista as pv
from pyvista import examples
sphere = pv.Sphere(center=(0, 0, 1))
cube = pv.Cube()
pl = pv.Plotter()
_ = pl.add_mesh(sphere, color='grey', smooth_shading=True, label='Sphere')
_ = pl.add_mesh(cube, color='r', label='Cube')
_ = pl.add_legend(bcolor='w', face=None)
pl.show()

# Alternatively provide labels in the plotter as a list.
pl = pv.Plotter()
_ = pl.add_mesh(sphere, color='grey', smooth_shading=True)
_ = pl.add_mesh(cube, color='r')
legend_entries = []
legend_entries.append(['My Mesh', 'w'])
legend_entries.append(['My Other Mesh', 'k'])
_ = pl.add_legend(legend_entries)
pl.show()

# Or use a dictionary to define them.
labels = {'Grey Stuff': 'grey', 'Red Stuff': 'red'}
pl = pv.Plotter()
_ = pl.add_mesh(sphere, color='grey', smooth_shading=True)
_ = pl.add_mesh(cube, color='red')
_ = pl.add_legend(labels, face='rectangle')
pl.show()

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

