Skript for transparent markers works in debugger stepwise mode but not as a whole skript

1 view (last 30 days)
Hey guys, I've written a script that plots dots in different sizes for different categories of data. I would now like to add some transparency to the dots to be able o better see the underlying colors. I've simplified my script like this:
h1 = plot([1:20],[1:20],'.', 'MarkerEdgeColor', [0 0 0], 'MarkerSize', 5);
hMarkers = h1.MarkerHandle;
hMarkers.EdgeColorData = uint8(255*[0;0;0;0.6]);
h2 = plot([1:20],[1:20],'.', 'MarkerEdgeColor', [0 0 0], 'MarkerSize', 2.5);
hMarkers = h2.MarkerHandle;
hMarkers.EdgeColorData = uint8(255*[0;0;0;0.6]);
It works when I'm in the debugger-mode and do it step by step but it won't work when I run the whole skript. Has anybody got an idea why?
Thanks a lot for your help. Cheers
  1 Comment
Guillaume
Guillaume on 23 Apr 2018

MarkerHandle is a hidden non documented property of line objects. Since it's not documented, matlab is free to do whatever it wants with it and yes, it does look like it's only updated at times, not instantly.

Even if your code worked in your current version, there'd be no guarantee that it work in the next version. You'd be better off finding an official method of doing what you want. Unfortunately, I'm not familiar enough with graphics to tell you what that is.

Sign in to comment.

Answers (1)

Paul Smits
Paul Smits on 4 Apr 2019
Matlab optimisation somehow destroys proper marker definitions.
Hack-solution: pause between creating the plot and fetching the markers.
h1 = plot([1:20],[1:20],'.', 'MarkerEdgeColor', [0 0 0], 'MarkerSize', 5);
pause(0.0000000001);
hMarkers = h1.MarkerHandle;
h2 = plot([1:20],[1:20],'.', 'MarkerEdgeColor', [0 0 0], 'MarkerSize', 2.5);
pause(0.0000000001);
hMarkers = h2.MarkerHandle;
hMarkers.EdgeColorData = uint8(255*[0;0;0;0.6]);
Is it dumb? Yes. Does it work? Yes.

Community Treasure Hunt

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

Start Hunting!