Search code examples
matlabmatlab-figure

Hidden contour property EdgePrims inaccessible for some edges


I am trying to change LineJoin for some lines in a MATLAB contour plot. When I modify the EdgePrims, only the "partial lines" are affected:

num_incs = 3;
x = linspace(-1,1,num_incs);
[Xa,Ya] = meshgrid(x,x);
Z = abs(Xa) + abs(Ya);

[C,hContour] = contour(Xa,Ya,Z,20,'LineWidth',4);

drawnow;
set(hContour.EdgePrims, 'LineStyle', 'dotted')
set(hContour.EdgePrims, 'LineJoin', 'miter')
drawnow;

produces the following: enter image description here

That is, I am setting the LineStyle and LineJoin only on the outer edges. How can I access the line properties of the middle lines as well?


Solution

  • There's a new hidden property for the contour object (matlab.graphics.chart.primitive.Contour): EdgeLoopPrims. This one contains handles to all the edges that form closed loops. EdgePrims now contains only handles to the lines that don't form a closed loop.

    set(hContour.EdgePrims, 'LineStyle', 'dotted')
    set(hContour.EdgeLoopPrims, 'LineStyle', 'dotted')
    

    As always with undocumented properties, this is bound to change at some point. Using this will limit your code use to specific versions of MATLAB. I tested this with R2021a.


    To explore hidden properties, simply convert the graphics handle to a struct: struct(hContour).