How to make '.' Markers transparent in a Scatter plot?

147 ビュー (過去 30 日間)
Zachary
Zachary 2021 年 1 月 22 日
回答済み: Zachary 2021 年 1 月 26 日
In R2016b, I am able to make Point ('.') Markers transparent in a Scatter plot by setting MarkerEdgeAlpha to a value < 1. For example:
%Generate 'n' random samples.
n = 10000;
x = randn(n,1);
y = randn(n,1);
%Plot.
figure
scatter(x, y, 'Marker', '.', 'MarkerEdgeAlpha', 0.5)
However in R2020b, it seems Point Markers can't be transparent. The same code produces:
Is there any way to make Point Markers transparent in a Scatter plot in R2020b, or was this feature deprecated? I'd rather use Point Markers than filled Circle Markers.

採用された回答

Zachary
Zachary 2021 年 1 月 26 日
Here's the answer from the Technical Support Case:
The current workaround for this is to use the 'o' marker symbol and divide its size to make it a similar size to the '.' marker symbol. This can be done by adding the following line to the code you sent in:
h = scatter(x, y, 'Marker', 'o', 'MarkerEdgeAlpha', 0.5);
h.SizeData = h.SizeData/9;

その他の回答 (1 件)

Constantino Carlos Reyes-Aldasoro
Constantino Carlos Reyes-Aldasoro 2021 年 1 月 22 日
Hello
Just tested this in R2019a and it works as for you, I have not yet upgraded to 2020.
Just an idea, try to grab the handle of the scatter plot
>> hs=scatter(x, y, 'Marker', '.');
Then you can investigate the properties of the handles directly, type hs. and then tab and a window with all the properties will appear, scroll down, in my case I found MarkerEdgeAlpha:
>> hs.MarkerEdgeAlpha
ans =
1
Which I could modify like this
>> hs.MarkerEdgeAlpha=0.5
hs =
Scatter with properties:
Marker: '.'
MarkerEdgeColor: 'flat'
MarkerFaceColor: 'none'
SizeData: 36
LineWidth: 0.5000
XData: [1×10000 double]
YData: [1×10000 double]
ZData: [1×0 double]
CData: [0 0.4470 0.7410]
Show all properties
>>
Perhaps you have to modify hs.MarkerFaceAlpha as well?
Hope that helps.
  2 件のコメント
Zachary
Zachary 2021 年 1 月 22 日
Unfortunately, that doesn't seem to work. When I try...
%Generate 'n' random samples.
n = 10000;
x = randn(n,1);
y = randn(n,1);
%Plot.
figure
h = scatter(x, y, 'Marker', '.', 'MarkerEdgeAlpha', 0.5, 'MarkerFaceAlpha', 0.5);
get(h, {'MarkerEdgeAlpha' 'MarkerFaceAlpha'})
... I get...
ans =
1×2 cell array
{[0.5000]} {[0.5000]}
It looks like the object properties MarkerEdgeAlpha and MarkerFaceAlpha are correctly set, but when the Marker is '.' (Point), they don't apply.
Constantino Carlos Reyes-Aldasoro
Constantino Carlos Reyes-Aldasoro 2021 年 1 月 25 日
Well, then it may be that this has been disabled, try changing to a circle marker of small size. Not the same as a point, but may be the second best.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeScatter Plots についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by