Bug when plotting 3 points in scatter MATLAB R2022a
13 ビュー (過去 30 日間)
古いコメントを表示
I have found a bug in the scatter function that I'm not sure how to tackle. If I have a scatter plot with only three elements I get the error: Invalid RGB triplet. Specify a three-element vector of values between 0 and 1. This is because the program thinks I am trying to input an RGB triplet, when I want them to fit within a broader context.
colormap("jet");
X = 1:7;
Y = X;
color_map = X;
scatter(X,Y,45,color_map,"o","filled")
X = 1:3;
Y = X;
color_map = X;
scatter(X,Y,45,color_map,"o","filled")
I can work arround the problem, by plotting each point twice.
X = 1:3;
Y = X;
color_map = X;
if length(X)==3
X = [X,X];
Y = [Y,Y];
color_map = [color_map,color_map];
end
scatter(X,Y,45,color_map,"o","filled")
0 件のコメント
採用された回答
Walter Roberson
2022 年 9 月 15 日
Because an RGB triple is permitted at that place, MATLAB needs to have some code to decide whether you are providing RGB or you are providing a vector with one entry per coordinate. The test for the vector length being 3 (RGB) is done first. But [1 2 3] is not valid RGB because the entries for RGB have to be in the range [0 1]
I think it would be even more confusing if MATLAB looked at the range of values and treated the row vector of length 3 differently depending on whether the values were all in the range [0 1] or not.
Historically this situation did not happen because scatter() required that x and y be column vectors, and was explicit that c had to be a column vector if it was one value per coordinate pair.
X = 1:3;
Y = X;
color_map = X(:);
scatter(X,Y,45,color_map,"o","filled")
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Scatter Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!