Merging 10 scatter plots produced with different RNG sequences
4 次查看(过去 30 天)
显示 更早的评论
Hi all
I have produced 10 scatter graphs which are similar and I wanted to merge the files into a scatter graph with range bars (i.e. Median, Upper Q, Lower Q)
I have the 10 figures saved as .fig and .m/.mat files.
Any tips for doing this please?
0 个评论
回答(3 个)
Julian Hapke
2016-4-4
you can access the data of each plot by
X=cell(10,1)
Y=X
for ii = 1:10
f = open('figure_ii.fig') % use the correct file names here
X{ii} = get(get(gca,'Children'),'XData')
Y{ii} = get(get(gca,'Children'),'YData')
close(f)
end
to calculate your new data use "quantile"
help quantile
also have a look at
help errorbar
to plot the ranges you calculated.
I hope this helps, otherwise you have to specify your question.
0 个评论
Om
2016-4-4
1 个评论
Julian Hapke
2016-4-5
I assume your variable names in each mat-file are the same, so if you just
load('example.mat')
it overrides your current values. So what you could do is just load your data into an array of structures:
data(10).median = []
data(10).lq = []
data(10).uq = []
for ii = 1:10
data(ii) = load('file.mat')
end
to get a vector of each array entry use
[data.median]
and so on
Om
2016-4-5
编辑:Om
2016-4-5
2 个评论
Julian Hapke
2016-4-7
编辑:Julian Hapke
2016-4-7
I'm not sure what I'm looking at in your plot and you have to be clearer about what is the data you have and what is the plot you want to see. my guess: you want an error bar plot for median, lq and uq, with 10 differing values for median lq and uq at each of 11 x-values. Here you go with some example data, that resembles your plot:
function tst
close all
%
% generate dummy data
data(10).median = [];
data(10).lq = [];
data(10).uq = [];
x = (0:10)';
for ii = 1:10
data(ii).x = (0:10)';
data(ii).median = (linspace(0,0.25,11)+(rand(1,11)*0.02-0.02).*linspace(0,1,11))';
data(ii).uq = (linspace(0,0.35,11)+(rand(1,11)*0.1-0.1).*linspace(0,1,11))';
data(ii).lq = (linspace(0,0.2,11)+(rand(1,11)*0.1-0.1).*linspace(0,1,11))';
end
% plot scatter of everything
figure(1)
hold all
for ii = 1:10
scatter(x,[data(ii).median],'g')
scatter(x,[data(ii).uq],'r')
scatter(x,[data(ii).lq],'b')
end
%
% calculate data for errorbars
errby = mean([data(:).median],2);
errbdwn = mean([data(:).median],2)-min([data(:).median],[],2);
errbup = max([data(:).median],[],2)-mean([data(:).median],2);
% plot errorbars
errorbar(x,errby,errbdwn,errbup,'Color','g');
%
errby = mean([data(:).uq],2);
errbdwn = mean([data(:).uq],2)-min([data(:).uq],[],2);
errbup = max([data(:).uq],[],2)-mean([data(:).uq],2);
errorbar(x,errby,errbdwn,errbup,'Color','r');
%
errby = mean([data(:).lq],2);
errbdwn = mean([data(:).lq],2)-min([data(:).lq],[],2);
errbup = max([data(:).lq],[],2)-mean([data(:).lq],2);
errorbar(x,errby,errbdwn,errbup,'Color','b');
end
Julian Hapke
2016-4-7
you mentioned earlier, that each of your 10 mat files contains 3 values, so I don't understand where all the plots in your picture come from, enlighten me.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!