set color in contour plot with specified colormap

I have a contour plot with only two value (3 and 5 for example), thus it should appear only two colors.
but I have a colormap with 6 values: cmb=jet(6);
I have plot the contour using command: [xc,yc]=contourf(X,Y,Z);
I want color the contour having value 3 with cmb(3,:), and color the contour having value 5 with cmb(5,:), is it possible to do this?
Thanks!
Yu

6 Kommentare

jonas
jonas am 4 Okt. 2018
Why dont you build the cmap with only those two rgb triplets?
Yu Li
Yu Li am 4 Okt. 2018
because I have a lot of contours need to be plot.
some have color 1,2, some have color 3,4, in order to make the colors consistent for all figures, i need to prescribe a colormap.
jonas
jonas am 4 Okt. 2018
Aha, I am not 100% sure what you want to do, but Im guessing you could achieve it by playing around with the clim
Yu Li
Yu Li am 4 Okt. 2018
not sure if this works. I will try to provide a test file.
jonas
jonas am 5 Okt. 2018
If you use the same limits for the cbar in every plot, then you can make comparisons between graphs using a single cbar.
Yu Li
Yu Li am 5 Okt. 2018
I tried to use the same limits for the colorbar, but the problem still exist. I post another topic here:
https://www.mathworks.com/matlabcentral/answers/422448-contourf-plot-different-display-problem
if you are interested could you please take a look?
Thanks!
Yu

Melden Sie sich an, um zu kommentieren.

Antworten (1)

ANKUR KUMAR
ANKUR KUMAR am 5 Okt. 2018
clc
clear
contourf(randi(6,5,5))
colormap(jet(5))
colorbar

Kategorien

Mehr zu Contour Plots finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 4 Okt. 2018

Kommentiert:

am 5 Okt. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by