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

135 views (last 30 days)
MathWorks Support Team on 23 Sep 2009
Answered: Karthick SK on 25 Aug 2021
The line object allows a limited subset of markers using the 'Marker' property. I would like to define a custom marker.

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.

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’ .
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)

MathWorks Support

### 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!