A legend pairs a plotted symbol or line with a label. Use one when a small number of discrete objects must be distinguished, such as selected grains, boundary classes, or reference directions.
In MTEX, legend entries are opt in. An object appears only when it is
plotted with a displayName. This is the opposite of MATLAB’s default
behaviour. It prevents markers, construction lines, and a colour-coded
background from each acquiring an unhelpful entry.
Choose the legend entries
Name only the objects that the reader needs to distinguish. This example names a point and a great circle. The pole at the centre remains unnamed.
from mtex import *
plot(vector3d.X, upper=True, displayName='point')
hold(True)
circle(vector3d.X, displayName='great circle', lineColor='r', lineWidth=2)
plot(vector3d.Z, marker='p', markerSize=30)
hold(False)
lgd = legend('show')

Read and adjust the result
The figure contains three plotted objects, but the legend has two entries.
The central star is visible in the axes but absent from the legend because
it has no displayName.
After MTEX has selected the entries, legend hands its options to matplotlib’s
legend. Calling it again
replaces the legend: an outside location avoids covering the spherical plot,
and a title explains what the entries classify.
lgd = legend('show', location='eastoutside', title='Geometry')

Choose the right colour guide
A legend represents discrete identities. When colour represents a numerical value, use a colour bar because it shows the complete value-to-colour scale. When colour represents a direction or an orientation, use a colour key that maps each possible direction or orientation to a colour. The next page introduces numerical colour scales; IPF Maps explains direction colour keys for orientation maps.
The matplotlib Legend properties provide further controls for placement and styling.
References
- S. R. Midway, Principles of Effective Data Visualization, Patterns 1 (2020), 100141, explains how selective legends and consistent visual scales make plots easier to compare.
Next
Continue with Color Maps to control how numerical values are translated into colours.
Technical Details
MATLAB moves and titles the legend by setting lgd.Location and lgd.Title.String on its
handle; a matplotlib legend cannot be moved outside its axes after it is made, so the page
calls legend a second time with location and title.
Citing this page.
This page is part of the documentation of
MTEX, a free and open
source MATLAB toolbox for analyzing and modeling crystallographic textures.
It was written by The MTEX Developers and is published at
https://mtex-toolbox.github.io/Legends_py.html.
If you use MTEX, or reuse text or figures from this page, in your research,
please cite
F. Bachmann, R. Hielscher, H. Schaeben: Texture Analysis with MTEX - Free and Open Source Software Toolbox, Solid State Phenomena 160 (2010), 63-68. 10.4028/www.scientific.net/SSP.160.63
BibTeX
@article{bachmann2010mtex,
author = {F. Bachmann and R. Hielscher and H. Schaeben},
title = {Texture Analysis with MTEX - Free and Open Source Software Toolbox},
journal = {Solid State Phenomena},
volume = {160},
pages = {63-68},
year = {2010},
doi = {10.4028/www.scientific.net/SSP.160.63},
url = {https://doi.org/10.4028/www.scientific.net/SSP.160.63}
}
Other papers describing specific MTEX methods are listed under Publications — please cite the one that best fits your application. The MTEX source code is licensed under the GNU General Public License v2.0; the text and figures of this documentation are licensed under CC BY 4.0, which permits reuse — including by automated systems — provided The MTEX Developers and this page are credited.