error bar on the graph
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
0 投票
hi
after i have plot between x y and z ( scatter3(x, y, z))
x=[2.6,5.2,14,23.3,28.3,2.6,5.2,14,23.3,28.3,2.6,5.2,14,23.3,28.3];
y=[3.5,6.9,17.7,29.1,35.2,3.5,6.8,17.5,28.7,34.8,3.4,6.6,16.9,27.6,33.5];
z=[450,450,450,450,450,350,350,350,350,350,250,250,250,250,250];
i want to make error bar for y in the same graph
and i have the standard deviation for y
which is ( 0.047140452, 0.047140452, 0.047140452, 0.124721913, 0.047140452, 0.047140452, 0.047140452, 0.047140452, 0.124721913, 0.124721913, 0.047140452, 0.047140452, 0.047140452, 0.124721913, 0.124721913)
so could you tell me what is the code for that
採用された回答
Star Strider
2020 年 4 月 21 日
The error bars are difficult to see, so I multiplied them by 10 here:
x=[2.6,5.2,14,23.3,28.3,2.6,5.2,14,23.3,28.3,2.6,5.2,14,23.3,28.3];
y=[3.5,6.9,17.7,29.1,35.2,3.5,6.8,17.5,28.7,34.8,3.4,6.6,16.9,27.6,33.5];
z=[450,450,450,450,450,350,350,350,350,350,250,250,250,250,250];
ysd = [0.047140452, 0.047140452, 0.047140452, 0.124721913, 0.047140452, 0.047140452, 0.047140452, 0.047140452, 0.124721913, 0.124721913, 0.047140452, 0.047140452, 0.047140452, 0.124721913, 0.124721913];
xr = reshape(x, [], 3);
yr = reshape(y, [], 3);
zr = reshape(z, [], 3);
ysdr = reshape(ysd, [], 3)*10;
figure
hold on
for k1 = 1:size(xr,2)
for k2 = 1:size(xr,1)
plot3((xr(k2,k1)*[1 1]), (yr(k2,k1)+ysdr(k2,k1)*[-1 1]), (yr(2,k1)*[1 1]), '-r')
plot3((xr(k2,k1)), (yr(k2,k1)), (yr(2,k1)), '.r')
end
end
hold off
view(-60,30)
grid on
xlabel('X')
ylabel('Y')
zlabel('Z')
% legend('Y\pm10\sigma')
Experiment to get the result you want.
16 件のコメント
ahmad albngali
2020 年 4 月 22 日
thank you so much
i have anothet question related to previouse one
know i have all x values x=[2.6,5.2,14,23.3,28.3,2.6,5.2,14,23.3,28.3,2.6,5.2,14,23.3,28.3];
and i have y values y=[3.5,6.9,17.7,29.1,35.2,3.5,6.8,17.5,28.7,34.8,3.4,6.6,16.9,27.6,33.5];
and i have z values z=[450,450,450,450,450,350,350,350,350,350,250,250,250,250,250];
so if i have
Z = 300
x = 20
Y = ???
to bring y i used the code in the bottom
YfromXZ = scatteredInterpolant(x(:), z(:), y(:))
queryx = 20;
queryz = 300;
matchingy = YfromXZ(queryx, queryz);
figure;scatter3(x, y, z); hold('on'); plot3(queryx, matchingy, queryz, 'r*');
my question is
is there any code to bring the error bar for new value for Y that related to Z = 300, x = 20 ?????
Star Strider
2020 年 4 月 22 日
As always, my pleasure!
‘my question is: is there any code to bring the error bar for new value for Y that related to Z = 300, x = 20 ?????’
There is. However that is so far from your data that I doubt the validity of the result.
I added ExtrapolationMethod to your code in order to induce it to extrapolate:
YfromXZ = scatteredInterpolant(x(:), z(:), y(:));
queryx = 20;
queryz = 300;
YfromXZ.ExtrapolationMethod = 'linear';
matchingy = YfromXZ(queryx, queryz);
Then the approach I took was a variation on your code:
errYfromXZ = scatteredInterpolant(x(:), z(:), y(:)+ysd(:));
errYfromXZ.ExtrapolationMethod = 'linear';
matchingyerr = errYfromXZ(queryx, queryz);
errY = (matchingyerr - matchingy)
producing:
errY =
0.097193007483870
That is appropriately larger than the ‘ysd’ values, however even at that I am not certain I would trust it.
.
ahmad albngali
2020 年 4 月 23 日
yes that what i want , and dont warry i will not trust it. ,
i know i am asking alo , but you rally help me
know i want to bring the error bar for both ( 1- all y values , 2- the new value for Y that related to Z = 300, x = 20 ) in one figure
i have attached an example of figure for x, y, z and alo a new value of Y when Z = 300, x = 20
so could you tell me the code that add a error bar for all y values and Y value as wll in the same figure


Star Strider
2020 年 4 月 23 日
With the extrapolated values, reshape will not work (added points must correspond to the existing (5x3) format), so the code needs to be rearranged slightly and the extrapolated values plotted separately, after the plotting loop:
x=[2.6,5.2,14,23.3,28.3,2.6,5.2,14,23.3,28.3,2.6,5.2,14,23.3,28.3];
y=[3.5,6.9,17.7,29.1,35.2,3.5,6.8,17.5,28.7,34.8,3.4,6.6,16.9,27.6,33.5];
z=[450,450,450,450,450,350,350,350,350,350,250,250,250,250,250];
ysd = [0.047140452, 0.047140452, 0.047140452, 0.124721913, 0.047140452, 0.047140452, 0.047140452, 0.047140452, 0.124721913, 0.124721913, 0.047140452, 0.047140452, 0.047140452, 0.124721913, 0.124721913];
xr = reshape(x, [], 3);
yr = reshape(y, [], 3);
zr = reshape(z, [], 3);
ysdr = reshape(ysd, [], 3)*10;
YfromXZ = scatteredInterpolant(x(:), z(:), y(:));
queryx = 20;
queryz = 300;
YfromXZ.ExtrapolationMethod = 'linear';
matchingy = YfromXZ(queryx, queryz);
figure;scatter3(x, y, z); hold('on'); plot3(queryx, matchingy, queryz, 'r*');
errYfromXZ = scatteredInterpolant(x(:), z(:), y(:)+ysd(:));
errYfromXZ.ExtrapolationMethod = 'linear';
matchingyerr = errYfromXZ(queryx, queryz);
errY = (matchingyerr - matchingy)
figure
hold on
for k1 = 1:size(xr,2)
for k2 = 1:size(xr,1)
plot3((xr(k2,k1)*[1 1]), (yr(k2,k1)+ysdr(k2,k1)*[-1 1]), (yr(2,k1)*[1 1]), '-r')
plot3((xr(k2,k1)), (yr(k2,k1)), (yr(2,k1)), '.r')
end
end
plot3(queryx*[1 1], matchingy+errY*[-1 1]*10, queryz*[1 1], '-g') % <- Added
plot3(queryx, matchingy, queryz, '.g') % <- Added
hold off
view(-60,30)
grid on
xlabel('X')
ylabel('Y')
zlabel('Z')
The extrapolated point and errorbar are plotted in green to make them more visible. (All the errorbars are multiplied by 10 because they would not otherwise be visible.)
.
ahmad albngali
2020 年 4 月 24 日
something was wrong with z values in figher 2 in attachment
for figher 1 ( attached as well ) the z was right , but for figure 2 the all values of z from 6.6 to 6.9 and this are wrong , shold be from 250 to 450 ( as figher 1 )
and the z value for Y was right in figure 2 , because as you can see the z 300 , but all z values for x and y in figure 2 are wrong
i am tring to find why this happens , but i cant do you have any idea


Star Strider
2020 年 4 月 24 日
When I went back and looked at my most recent code, I realize there was a typographical error I did not catch. The plot3 calls should be:
plot3((xr(k2,k1)*[1 1]), (yr(k2,k1)+ysdr(k2,k1)*[-1 1]), (zr(2,k1)*[1 1]), '-r')
plot3((xr(k2,k1)), (yr(k2,k1)), (zr(2,k1)), '.r')
I copied the ‘xr’ part of those to the z position to avoid re-typing them, and then mistyped ‘yr’ instead of ‘zr’. I was concentrating on getting the error bars to plot correctly, and overlooked that.
Fixed now. The plot3 calls after the loop are correct.
ahmad albngali
2020 年 4 月 24 日
yes , now working great
thank you so much
is there any solution to show the error bar appear in the figure without multiplied by 10
Star Strider
2020 年 4 月 24 日
As always, my pleasure!
The error bars are there, however they are so small with respect to the amplitudes of the other variables that they are essentially impossible to see without zooming in on each plotted data point. I multiplied them by 10 to check the code to be certain they are plotting correctly. It is not necessary to multiply them at all.
ahmad albngali
2020 年 4 月 24 日
But if I want to put it In my thesis And I want to show people the error bar I have to multiplied by 10 Right ? That was my question is there any other cases to show the error bar without multiplied by 10 Show him the right data without multiplied by 10
Star Strider
2020 年 4 月 24 日
Just put in the legend that the errorbars aare multiplied by 10 (or whatever number you choose), since the relative sizes may be more important than the absolute sizes, depending on what you are demonstrating. I am not certain how best to show the error bars without multiplying them.
Note that this line:
plot3((xr(k2,k1)), (yr(k2,k1)), (zr(2,k1)), '.r')
puts a ‘.’ in the centre of the errorbars to show where it is. One possibility is to replace that by a ‘+’, although just leaving those out might work as well, so that only the error bars themselves are presented. One way to multiply them might be to use 1.96 (to show them as the 95% confidence intervals from the normal distribution) or the result of tinv since that might be more appropriate (and likely larger than 1.96), or confidence intervals based on another distribution, depending on what that distribution is (since I do not know what the data themselves represent).
ahmad albngali
2020 年 6 月 16 日
hi as you remember i used this code
This code was used to find the Relationship of DEq, CTDIvol and scanning length, also the code was used to show the error bar for DEqvalues (The error bars for all DEqvalues are difficult to see in the graph , so I multiplied them by 5)
% x= CTDIv
x=[2.6,5.2,14,23.3,28.3,2.6,5.2,14,23.3,28.3,2.6,5.2,14,23.3,28.3 ];
% y= planar average equilibrium dose (DEq)
y=[3.5,6.9,17.7,29.1,35.2,3.5,6.8,17.5,28.7,34.8,3.4,6.6,16.9,27.6,33.5 ];
% z= scanning length
z=[450,450,450,450,450,350,350,350,350,350,250,250,250,250,250];
% ysd= DEq standard deviation
ysd = [0.047140452, 0.047140452, 0.047140452, 0.124721913, 0.047140452, 0.047140452, 0.047140452, 0.047140452, 0.124721913, 0.124721913, 0.047140452, 0.047140452, 0.047140452, 0.124721913, 0.124721913];
xr = reshape(x, [], 3);
yr = reshape(y, [], 3);
zr = reshape(z, [], 3);
ysdr = reshape(ysd, [], 3)*5;
%for visualisation
figure
hold on
for k1 = 1:size(xr,2)
for k2 = 1:size(xr,1)
plot3((xr(k2,k1)*[1 1]), (yr(k2,k1)+ysdr(k2,k1)*[-1 1]), (zr(2,k1)*[1 1]), '-r')
plot3((xr(k2,k1)), (yr(k2,k1)), (zr(2,k1)), '.r')
end
end
hold off
view(-60,30)
grid on
so my question
the Error bars are too small. and i want to Increase the dot size and fit a grid or lines to the dots ??
Star Strider
2020 年 6 月 16 日
Experiment with the 'LineWidth' and 'MarkerSize' properties to get the result you want.
ahmad albngali
2020 年 6 月 16 日
Where I have to put the 'LineWidth' and 'MarkerSize' in the code Can you add it to me in the code ?
Star Strider
2020 年 6 月 17 日
ahmad albngali
2020 年 6 月 22 日
hi i try to do it but it is confusing
could you please show me hoe i do it in my examble ( in my code )
Star Strider
2020 年 6 月 22 日
Add them to the plot3 calls:
plot3((xr(k2,k1)*[1 1]), (yr(k2,k1)+ysdr(k2,k1)*[-1 1]), (zr(2,k1)*[1 1]), '-r', 'LineWidth',1.5)
plot3((xr(k2,k1)), (yr(k2,k1)), (zr(2,k1)), '.r', 'MarkerSize',10)
so the complete code is now:
% x= CTDIv
x=[2.6,5.2,14,23.3,28.3,2.6,5.2,14,23.3,28.3,2.6,5.2,14,23.3,28.3 ];
% y= planar average equilibrium dose (DEq)
y=[3.5,6.9,17.7,29.1,35.2,3.5,6.8,17.5,28.7,34.8,3.4,6.6,16.9,27.6,33.5 ];
% z= scanning length
z=[450,450,450,450,450,350,350,350,350,350,250,250,250,250,250];
% ysd= DEq standard deviation
ysd = [0.047140452, 0.047140452, 0.047140452, 0.124721913, 0.047140452, 0.047140452, 0.047140452, 0.047140452, 0.124721913, 0.124721913, 0.047140452, 0.047140452, 0.047140452, 0.124721913, 0.124721913];
xr = reshape(x, [], 3);
yr = reshape(y, [], 3);
zr = reshape(z, [], 3);
ysdr = reshape(ysd, [], 3)*5;
%for visualisation
figure
hold on
for k1 = 1:size(xr,2)
for k2 = 1:size(xr,1)
plot3((xr(k2,k1)*[1 1]), (yr(k2,k1)+ysdr(k2,k1)*[-1 1]), (zr(2,k1)*[1 1]), '-r', 'LineWidth',1.5)
plot3((xr(k2,k1)), (yr(k2,k1)), (zr(2,k1)), '.r', 'MarkerSize',10)
end
end
hold off
view(-60,30)
grid on
Change the values to create the result you want.
.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Just for fun についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
