scatter plot with patches
显示 更早的评论
My data has some concentrations(y axis) ranging from 0-600 mostly and one area values aruond 30,000 at 4 different locations. I ran this code works fine for random matrices but the background gray patches dissapear when I enter my observation data(tried to change the x y values but cann't seem to get how it works). Also as my data on y axis varies so much I want to represent in log scale or anyway it could be clearly visualized.
sites = compose("%s%d",["A" "B" "C" "D"].',1:6).';
sites = sites(:);
sites([4 5 6 10 11 12]) = [];
n_sites_per_group = [3 3 6 6];
elements = ["Cr" "Mn" "Mo" "Ni" "V" "Co" "Zn" "Cu" "Ga" "Cd" "Sn" "zr" "Pb" "Fe"];
n_sites = numel(sites);
n_elements = numel(elements);
data=num; %data ranges from 0 to 30,000 imported from excel
colors = [ ...
0 0 1; ...
0 0.6 0; ...
1 0 0; ...
0.6 0.6 0; ...
0.6 0.6 0.6; ...
0.6 0.6 0; ...
1 0 1;...
1 1 0;...
1 0.6 1;...
1 0.6 0.6;...
0.6 1 0.6;...
1 1 0.6;...
0 0 0;...
0 1 0;];
markers = 'o+*.x_|sd^v><p';
hold on
lines = zeros(1,n_elements);
for ii = 1:n_elements
lines(ii) = line(1:n_sites,data(:,ii), ...
'LineStyle','none', ...
'Marker',markers(ii), ...
'Color',colors(ii,:), ...
'MarkerFaceColor',colors(ii,:), ...
'DisplayName',elements(ii));
end
x_edges = [0 0.5+cumsum(n_sites_per_group(1:end-1)) n_sites+1]
xline(x_edges(2:end-1),'Color',[0.4 0.4 0.4]);
text((x_edges(1:end-1)+x_edges(2:end))/2,2*ones(1,numel(n_sites_per_group)), ...
["AHF" "AHA" "AHR1" "AHR2" ], ...
'VerticalAlignment','top', ...
'HorizontalAlignment','center', ...
'FontWeight','bold', ...
'FontSize',8);
xlim(x_edges([1 end]));
ylim([0 30,000]);
xlabel('Sampling site','FontWeight','bold');
ylabel('Conc-mg/L','FontWeight','bold');
set(gca(), ...
'Layer','top', ...
'Box','on', ...
'XTick',1:n_sites, ...
'XTickLabels',sites, ...
'TickLength',[0.005 0.005]);
y= (5:-.1:0)+[0;1;1;0] ; %from here I am unable to get it
x=repmat([0;0;n_sites+[1;1]],1,6);
c = repmat(linspace(0.5,0.95,6).',1,3);

p = patch( ...
'XData',x, ...
'YData',y, ...
'FaceColor','flat', ...
'FaceVertexCData',c, ...
'EdgeColor','none');
ch = get(gca(),'Children');
set(gca(),'Children',[ch(ch ~= p); p]);
legend(lines,'Location','SouthEast','NumColumns',2);
2 个评论
Walter Roberson
2022-6-2
which plot is to have log y? I notice that there are negative y for the first plot; you would have problems plotting that with log.
Roja Eliza
2022-6-2
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
