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!