How to improve readability of this contour / pcolor plot?

조회 수: 7 (최근 30일)
iontrap
iontrap 2023년 9월 14일
댓글: iontrap 2023년 9월 17일
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.

채택된 답변

Nathan Hardenberg
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);
Current plot held
% 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 CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by