matlab contourf with gradual change of color

14,917

Solution 1

Cinico's solution didn't work for me. Here's what I used:

% Set Data
data = (1:100)'*(1:100);

figure;
subplot(1,2,1)
% Binned Color
contourf(data);
subplot(1,2,2)
% Gradual Color
pcolor(data);
hold on;
shading interp; 
contour(data,'LineColor','k')

Output:

enter image description here

Solution 2

try shading interp command after the plot is done

but...

the most probable thing is that your data is not "gradual". What I mean is: either you have value 2 or 4 or 10 etc, not 2.2 or 4.6 or 10.1 etc.

So, you could not have the intermediate colours because that would mean that you would have intermediate values (which you don't).

Share:
14,917
nos
Author by

nos

Hello fellow programmers! I maintain open source software and blog about science and technology in my spare time. Main projects: gita: A command-line tool to manage multiple git repos (1000+ ⭐) blog where I write about math, physics, coding, and hobbies youtube channel: productivity hacks and coding tips

Updated on September 09, 2022

Comments

  • nos
    nos over 1 year

    folks,

    I have an image matrix and created the following figure using

    contourf(my_matrix)
    colorbar
    

    enter image description here

    Is it possible to make the color change gradually between the contour lines, instead of filling these spaces with solid color?

    Thanks very much for your help.