How do I use custom markers for a line object in a MATLAB plot?

119 views (last 30 days)
The line object allows a limited subset of markers using the 'Marker' property. I would like to define a custom marker.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 23 Sep 2009
The ability to use custom markers for line objects is not available in MATLAB.
To work around this issue, you can find a font that has a character similar to your desired marker. Then you can use the TEXT command to create text objects at the desired marker locations. This is very similar to using the PLOT command. For example:
% Define the font and desired character
font = 'Wingdings';
m = 'J';
% Make some arbitrary data
x = 0:.5:2*pi;
y = sin(x);
% Use TEXT to plot the character along the data
text(x,y,m,'fontname',font,'color','red')
% Manually set axis limits, since TEXT does not do this for you
xlim([min(x) max(x)])
ylim([min(y) max(y)])
For more ideas on character symbols you can use, see the Related Solution.

More Answers (1)

Karthick SK
Karthick SK on 25 Aug 2021
It does not work in 'Windows' machine.
The alternative suggestion is to use one of the default fonts available in Matlab like ‘Zapf Dingbats’.
By using the decimal code, Matlabprints the actual text. On the other hand, while using the hexadecimal code, it prints the corresponding symbol.
For example,
text(0.5,0.5,char(065),'fontname','ZapfDingbats','fontsize',10); % char in decimal code
prints the corresponding ZapfDingbats character, whereas
text(0.5,0.5,char(0x2721),'fontname','ZapfDingbats','fontsize',10); % char in hexadecimal code
prints the corresponding ZapfDingbats graphic text.
The relevant decimal and hexadecimal values can be found in the following links:
Use the table given in the Unicode blocks for ‘Zapf Dingbats’ .
  1. https://en.wikipedia.org/wiki/Zapf_Dingbats
  2. https://help.adobe.com/en_US/framemaker/2015/using/using-framemaker-2015/Appendix/frm_character_sets_cs/frm_character_sets_cs-5.htm
The easy way to achieve this is by slightly modifying the code.
For using only letters,
clearvars; close all; figure;
% Define the font and desired character
font = 'ZapfDingbats';
m = char(065);
% Make some arbitrary data
x = 0:.5:2*pi;
y = sin(x);
% Use TEXT to plot the character along the data
text(x,y,m,'fontname',font,'color','red')
% Manually set axis limits, since TEXT does not do this for you
xlim([min(x) max(x)])
ylim([min(y) max(y)])
For using corresponding graphic symbol,
clearvars; figure;
% Define the font and desired character
font = 'ZapfDingbats';
m = char(0x2721);
% Make some arbitrary data
x = 0:.5:2*pi;
y = sin(x);
% Use TEXT to plot the character along the data
text(x,y,m,'fontname',font,'fontsize',20,'color','red')
% Manually set axis limits, since TEXT does not do this for you
xlim([min(x) max(x)])
ylim([min(y) max(y)])
(Credits: Kannan Munusamy. My friends found this way as efficient and the credits go to him)

Categories

Find more on Labels and Annotations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!