gramm icon indicating copy to clipboard operation
gramm copied to clipboard

Problem and solution regarding marker alpha

Open MxMarx opened this issue 6 years ago • 4 comments

I've been having a few problems setting the 'alpha' parameter in geom_point.

When I run this code, the points in the resulting figure become transparent for less than a second, but quickly reverts to opaque as the figure is created

load example_data;
figure
g=gramm('x',cars.Horsepower,'y',cars.MPG,'subset',cars.Cylinders~=3 & cars.Cylinders~=5);
g.geom_point('alpha', 0.2);
g.draw

I did manage to find a solution, but I'm not sure why it works and there's probably a much better way to implement it.

If I add pause(0.5) to line 407 in draw.m where the subplot is created, the code runs perfectly and the points remain transparent.

I'd guess that creating the axis or making an axes current takes some time and doesn't block the code, but I don't know the specifics it.

I'm perfectly willing to wait half a second per axis, but I thought you should know about this if you didn't.

Thanks, Russell

MxMarx avatar Jan 15 '19 19:01 MxMarx

Hi Russell,

Thanks for the heads up. Point alpha is not something "officially " supported by Matlab, so it's no surprise that it's weird sometimes. I have to say that on my Mac and my Matlab version I don't need your trick to get correct alpha displayed (saving it is another matter) ! I'll leave your comment open in case someone is looking for a similar solution.

piermorel avatar Jan 22 '19 14:01 piermorel

Hey Pier, Russell,

I've encountered the same problem, and the fix mentioned by Russell doesn't work for me. I have, however, found a different workaround, which I'm sorry to say is more complicated.

The opacity issues seem to come from the first draw() call somehow - so, if you want to plot transparent points and then an opaque fit, then the points become opaque. But if you wanted to plot an opaque fit and then transparent points, it will work.

If you need a transparent base and an opaque cover, my workaround is to introduce a "dummy" first layer that contains e.g. a thin opaque line in the first draw(). The transparent points can then be drawn in an update(), and the true opaque line drawn in a second update(). I don't know why this works, but it does appear to do so.

Loving the package, by the way. Superb work.

Best, Paul

P.S. if you're working on any updates, can I suggest an option for hollow points, or a separate outline option?

P.P.S. just noticed there is already an update from Nicholas. Will apply. Thanks again!

pgratrex avatar Jan 09 '20 22:01 pgratrex

Hi all

I've also encountered the same one. In my case, both of solution as shown by Russel and Pier couldn't work.

The factor worked for my case is the figure size.

With figure('Position',[100 100 1100 400]);, alpha didn't affect to opacity. But, with figure('Position',[100 100 900 900]);, alpha sucessfully worked.

I think this might be related to "pause(0.5) solution", speed of drawing, but I don't know.

anyway, thanks for good product! I'm loving this.

Thanks, Yuta

YutaKudo avatar Mar 04 '21 06:03 YutaKudo

Not sure this aids diagnosing the issue. I am running gramm on a .mlx file, I see how the alpha works in the animation but then it reverts back to normal when the block has finished running.

matiasandina avatar Nov 29 '21 21:11 matiasandina

I've been having a few problems setting the 'alpha' parameter in geom_point.

When I run this code, the points in the resulting figure become transparent for less than a second, but quickly reverts to opaque as the figure is created

load example_data;
figure
g=gramm('x',cars.Horsepower,'y',cars.MPG,'subset',cars.Cylinders~=3 & cars.Cylinders~=5);
g.geom_point('alpha', 0.2);
g.draw

I did manage to find a solution, but I'm not sure why it works and there's probably a much better way to implement it.

If I add pause(0.5) to line 407 in draw.m where the subplot is created, the code runs perfectly and the points remain transparent.

I'd guess that creating the axis or making an axes current takes some time and doesn't block the code, but I don't know the specifics it.

I'm perfectly willing to wait half a second per axis, but I thought you should know about this if you didn't.

Thanks, Russell

Hi, I have experienced the same problem (Matlab 2018b with Mac 13.1, Ventura). I don't know why this happened, but adding 'pause(0.5)' in draw.m works for me.

P.S. but the same issue happened again when I try to save this figure (*.pdf). :(

Thanks, Suhwan.

SuhwanGim avatar Jan 15 '23 11:01 SuhwanGim

Hi @MxMarx , @pgratrex @matiasandina @SuhwanGim @YutaKudo Thank you all for looking into this. As you can see I was away from gramm for a while, but I now have the opportunity to do some work on it. For alpha what is implemented in gramm dates from before it became officially supported in Matlab, hence the quirks I suppose. I will look into making it work properly.

piermorel avatar Jan 17 '24 15:01 piermorel

This should be fixed in 16aeeaff29c3c388db96aea5e2dbfa7300ba6e28 which now uses only documented features for alpha. As a side effect it changes the type of graphic object generated by geoms.

piermorel avatar Jan 17 '24 17:01 piermorel