How to improve readability of this contour / pcolor plot?

4 visualizaciones (últimos 30 días)
iontrap
iontrap el 14 de Sept. de 2023
Comentada: iontrap el 17 de Sept. de 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.

Respuesta aceptada

Nathan Hardenberg
Nathan Hardenberg el 15 de Sept. de 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]);

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by