フィルターのクリア

How to improve readability of this contour / pcolor plot?

2 ビュー (過去 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]);
  1 件のコメント
iontrap
iontrap 2023 年 9 月 17 日
That was much easier than expected! Thanks.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by