File Exchange

image thumbnail


version 1.2.2 (2.02 KB) by Jonah Pearl
Make a legend with customized colors and labels, independent of plotted data.


Updated 14 May 2020

View Version History

View License

[] = MAKE_CUSTOM_PATCH_LEGEND(colors, labels)
MAKE_CUSTOM_PATCH_LEGEND will plot a custom legend on the current figure.
It uses a hack involving invisible patch objects that I don't understand.
COLORS: either a cell array of n MATLAB color strings ('r', 'b', 'k', etc.);
or a column vector of n scalars, which will index into the current colormap;
or a n x 3 matrix of RGB values for each patch.
LABELS: a cell array of n string labels for your legend.
VARARGIN: name/value arguments to pass to legend().

Cite As

Jonah Pearl (2021). make_custom_patch_legend (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (1)

Jonah Pearl

Seems to have worked.

MATLAB Release Compatibility
Created with R2018b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!