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

1 次查看(过去 30 天)
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 个评论
Guillaume
Guillaume 2018-4-23

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.

请先登录,再进行评论。

回答(1 个)

Paul Smits
Paul Smits 2019-4-4
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.

类别

Help CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by