Search code examples
matlabmarkeruser-defined

Matlab plot marker label (NodeLabel) property


Is there any way to access and set plot marker property in Matlab?

In some case especially when user defined Marker is used (like the image below), it is necessary to set NodeLabel's position, font and color, to make it distinct in the figure.

enter image description here

g_obj = graph(sources, targets);
gp = plot(g_obj);

gp is a Matlab GraphPlot object and even though gp.NodeLabel is located in above layer, but has visual interference with user-defined markers' black lines and for example AL1, NAL1 and S6R2 are not readable.

Is there any way to set the Marker's font and position, using the gp itself?


Solution

  • I tried this solution which gives some flexibility, just copied the position and labels then used text instead of NodeLabel with more flexibility in color, font and etc.

    %%---
    gp = plot(graph_object,'Layout','layered');
    labels = gp.NodeLabel;
    gp.NodeLabel = [];
    gp.LineStyle = 'none'; gp.Marker = 'none';
    
    for i=1:length(labels)
        text(gp.XData(i)+2, gp.YData(i)-5,labels(i),...
           'fontsize', 8,'FontName', 'Arial', 'Color',[0 0.25 0],...
           'FontWeight', 'bold');
    end
    

    enter image description here