image thumbnail

Adjust legend marker size

version 1.5.0.0 (1.2 KB) by Andreas
A function to adjust the marker size of the current legend without changing the plot marker size

3.6K Downloads

Updated 10 Jan 2018

View License

Usage:
legendmarkeradjust(markersize)
In some cases you might want a small sized marker on a scatter plot, but in order to see the different colors in the legend, the marker must be larger in size.
This function resizes the marker independently from the marker size of the scatter plot.
Example:
plot(1:100,'.');
hold on
plot([1:100].^1.5,'.r')
legend('First','Second')
legendmarkeradjust(20)
Enjoy
*** Warning concerning usage in versions later than 2014a:
This function works best for MATLAB 2014a and earlier.
For later versions, after using this function, no further changes of the legend are possible except its location. Make sure that this is the final modification you want to do to your legend.
In general I cannot guarantee that it will work as smoothly as in 2014a and earlier versions because the solution is somehow cumbersome (recreating the legend in order to have the possibility of independent adjustment of sizes).

Cite As

Andreas (2021). Adjust legend marker size (https://www.mathworks.com/matlabcentral/fileexchange/46105-adjust-legend-marker-size), MATLAB Central File Exchange. Retrieved .

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

Inspired: setLegMarkSize(legendSizeDesired)

Community Treasure Hunt

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

Start Hunting!