
How can I use a custom marker for plot or alternatively add a text item in the legend?
18 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dear all,
I would like to add data points to my plot with a letter instead of the default markers that are available in Matlab. So far the only way I could get that working was to use
text(x,y,'A','FontSize',12,'Interpreter','latex')
but sadly this does not produce an entry in the legend. Therefore I'm in need of a solution for either adding the text item to the legend (so with the letter 'A' as icon) or for a way to change the marker of plot(x,y) to the letter 'A'.
By the way, the plot is likely to evolve so it would be good if it's really implemented with the use of legend and/or plot. I thought of adding some text as a "fake legend" but that sounds like a lot of work that would have to be done again every time the legend changes. Moreover, if I find a good solution I intend on using it on other plots in the future.
Many thanks in advance!
Julien.
0 commentaires
Réponses (1)
Ameer Hamza
le 23 Mai 2018
Modifié(e) : Ameer Hamza
le 23 Mai 2018
One solution is to create an empty line i.e. the line will not appear on the screen but the handle still exists. Then you can give a legend to the empty line and it will appear as if the legend belongs to the text object. For example, try this
plot(1:10, 1:10);
ax = gca;
hold(ax);
text(1:10, 1:10, 'A', 'FontSize',12,'Interpreter','latex')
l = line(); % creating an empty line
l.XData = []; % remove its points from the axes
l.YData = [];
l.Color = [0 0 0];
legend({'axtual plot', 'text markers'});
The result will be like this

Voir également
Catégories
En savoir plus sur Legend dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!