3

I read the blog post on assigning transparency to plot markers. I tried the code on a simple example and all was well. Then I tried a tight loop, plotting a single point at a time (doing this to assign a different color to each point in the graph), and invariably within a few loop cycles, when I grab the "plothandle.MarkerHandle", it's empty. In these cases, the class of this empty object is Matlab.graphics.GraphicsPlaceholder while when the operation is successful, the class is: matlab.graphics.primitive.world.Marker

The basic loop follows. colormatrix assigns a [r,g,b] color to each data point.

hold on
opacity = 0.5; 
for jk = 1:numel(idx
  tmph = plot(foox(jk),fooy(jk),'o','color',colormatrix(jk,:) );
     tmpk = tmph.MarkerHandle;

     tmpk.FaceColorData = uint8(double(tmpk.EdgeColorData).* [1,1,1,opacity]');
     tmpk.EdgeColorData = uint8(double(tmpk.EdgeColorData).* [1,1,1,opacity]');

end

I've tried things like clearing variables every loop, putting in a delay timer, and so on, with no luck. I'm using Matlab R2015a.

EDIT: here's a simple example. What I seem to be finding is that if I run the entire script, it always fails. If I break it into two pieces where noted and execute the second section with a separate key stroke (ctrl-enter or selectall/F9 in the IDE editor), everything works. And yes, I'm aware that "undocumented features" are risky , but since MathWorks still hasn't figured out that allowing transparency -- and indexed color assignments -- are good things for the plot function, I'm still looking for a better workaround than using patch to draw each data point.

figure
xfoo = 1:10;
yfoo = 2*xfoo;
tmph = plot(xfoo,yfoo,'p','color',[1,0,1]);
hold on
opacity = 0.7; 
%  wait a while here. 
tmpk = tmph.MarkerHandle;
tmpk.FaceColorData = uint8(double(tmpk.EdgeColorData).*[1,1,1,opacity]');
tmpk.EdgeColorData =  uint8(double(tmpk.EdgeColorData).*[1,1,1,opacity]'); 
Carl Witthoft
  • 20,573
  • 9
  • 43
  • 73
  • 3
    Please provide a reproducible example. – sco1 Jan 28 '16 at 19:03
  • The blog post is from Nov 2014. Are you sure the undocumented features still apply to 2015a? That's the thing with undocumented features: they can go away any day. See [this comment](http://undocumentedmatlab.com/blog/plot-markers-transparency-and-color-gradient#comment-348846), the solution to which didn't work for [this user](http://undocumentedmatlab.com/blog/plot-markers-transparency-and-color-gradient#comment-348984) – Andras Deak -- Слава Україні Jan 28 '16 at 19:09
  • @AndrasDeak it works "some of the time" -- that's what's aggravating me. Matlab's internals are acting inconsistently. – Carl Witthoft Jan 28 '16 at 19:30

1 Answers1

4

The fact that the script seems to work if you wait a bit between the plot and the retrieval of tmph.MarkerHandle suggests that you have the same issue that was reported on the blog by a user running R2014b. Yair suggested to call drawnow after the plot:

figure
xfoo = 1:10;
yfoo = 2*xfoo;
tmph = plot(xfoo,yfoo,'p','color',[1,0,1]);
hold on
opacity = 0.7; 
drawnow;
tmpk = tmph.MarkerHandle;
tmpk.FaceColorData = uint8(double(tmpk.EdgeColorData).*[1,1,1,opacity]');
tmpk.EdgeColorData =  uint8(double(tmpk.EdgeColorData).*[1,1,1,opacity]'); 

The workaround didn't work for a user running R2015a, which doesn't sound promising, but the fact that waiting seems to help for you, is encouraging.