Fix Color to Value in Contour
11 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi,
I try to plot a contour and a 2d graph in one plot. I do this for different data sets. Atm my contour colours are changing depending on the maximum value in the contour of the specidic data set. For ease of comparison I would like every contour to use the same colour scheme; i.e. the number 8 should have the same colour regardless as whether the maximum value of that data set is 10 or 20. Atm my maximum colour is always yellow and thus changes the colours of each value below. How can I ensure that cetrain numbers are keeping their colour value please?
contourLevels = [1 2 4 6 8 10 12 14 16 18 20 22 24];
figure(13)
yyaxis left
set(gca,'YColor','black')
[C3,h3]=contour(X, Y, Q, contourLevels,'LineWidth',2);
hold on
plot(eta,zeta,'black','LineWidth',2)
hold on
ylabel('Y [m]')
yticks(0:0.2:0.6)
xlabel('\eta')
yyaxis right
set(gca,'YColor','black')
plot(x,y,'red','LineWidth',2)
shading interp
cbr=colorbar('southoutside');
set(cbr,'YTick',[0 1 2 4 6 8 10 12 14 16 18])
set(cbr,'ylim',[0 18])
grid on
ax = gca;
set(gca,'FontSize',24);
ax.YAxis(2).Direction = 'reverse';
ax.YAxis(2).Limits=([-4,0]);
ax.YAxis(1).Limits=([0,0.04]);
ax.YAxis(1).TickValues=([0,0.02,0.04,0.06,0.08, 0.1]);
xlim([0 1.2])
ylabel('p')
title(' X/C= 0.5')
0 Commenti
Risposte (1)
Prabhan Purwar
il 14 Ott 2019
Hi,
The contour plot uses the current color map of the figure to decide the color pattern. A custom colormap can be used to plot a contour graph with a specific color pattern as shown:
cmap = [1 0 1; % magenta
0 1 1; % cyan
1 1 0; % yellow
0 0 0; % black
0 0 1; % blue
0 1 0; % green
1 0 0]; % red
data = rand(10);
data = (data - 0.5) * 225;
contourLevels = [-60 -30 -20 0 20 30 60];
figure();
contour(data, contourLevels, 'LineWidth', 2);
% Use the custom colormap
colormap(cmap);
colorbar()
set(gca, 'clim', [-60 60])
0 Commenti
Vedere anche
Categorie
Scopri di più su Contour Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!