How to improve readability of this contour / pcolor plot?

7 vues (au cours des 30 derniers jours)
iontrap
iontrap le 14 Sep 2023
Commenté : iontrap le 17 Sep 2023
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.

Réponse acceptée

Nathan Hardenberg
Nathan Hardenberg le 15 Sep 2023
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 commentaire
iontrap
iontrap le 17 Sep 2023
That was much easier than expected! Thanks.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Contour Plots dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by