How to improve readability of this contour / pcolor plot?
7 次查看(过去 30 天)
显示 更早的评论
I am following the procedure from https://www.mathworks.com/matlabcentral/answers/524254-pcolor-and-contour-in-the-same-map to overlay a pcolor plot with contour lines. Part of this solution is to make the FaceAlpha of the pcolor plot less than 1 so that the contour plot appears, however this results in poor readability of the contour lines and their labels.
Is there a better way to overlay the contour lines so they appear more clearly? It seems that with this method, either the pcolor plot or the contour lines have good visibility, but not both.
Code:
data = readtable('for_testing.txt');
J = 10;
x = data{:,1}; y = data{:, 2}; z = data{:, 3}; c = data{:, J}; % check the number of columns of your input.
a = unique(x); s = unique(y); g = unique(z);
data_sorted = sortrows(data, 1:J);
v = reshape(data_sorted{:,J}, length(us), length(g));
f=figure;
f.Position = [100 100 1340 940];
ax = axes();
hold(ax);
l=contour(s,g,v,[0.008 0.02 0.05 0.1 0.3],'k','LineWidth',1.8,'ShowText','on','LabelSpacing',300);
p=pcolor(s,g,v);
p.FaceAlpha = 0.85;
axis([s(1) 70 g(1) g(120)]);
shading interp;
colormap(flipud(jet))
c=colorbar();
caxis([0.0 0.5]);
Resulting figure is attached.
0 个评论
采纳的回答
Nathan Hardenberg
2023-9-15
There seems to be an issue with the color that gets plotted over the contour. I just plotted the contour afterwards with good results. (Small note: There is an error in your code: "length(us)" has to be "length(s)")
data = readtable('https://mathworks.com/matlabcentral/answers/uploaded_files/1482526/for_testing.txt');
J = 10;
x = data{:,1}; y = data{:, 2}; z = data{:, 3}; c = data{:, J}; % check the number of columns of your input.
a = unique(x); s = unique(y); g = unique(z);
data_sorted = sortrows(data, 1:J);
v = reshape(data_sorted{:,J}, length(s), length(g));
f=figure;
%f.Position = [100 100 1340 940]; % commented for better readability in the browser (can be removed)
ax = axes();
hold(ax);
% removed contour(...) from here
p=pcolor(s,g,v);
p.FaceAlpha = 0.85;
axis([s(1) 70 g(1) g(120)]);
shading interp;
colormap(flipud(jet))
% moved contour(...) here VVVV
l=contour(s,g,v,[0.008 0.02 0.05 0.1 0.3],'k','LineWidth',1.8,'ShowText','on','LabelSpacing',300);
c=colorbar();
caxis([0.0 0.5]);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Contour Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!