Info

This question is closed. Reopen it to edit or answer.

Hi, I have shaped an area between two graphs with one color, but I want that the shade area changes the color with rising yaxis.

1 view (last 30 days)
My yaxis is temperature from 0 to 40, so in the beginning it should be blue or green and by reaching 40 it should be dark red and color changes by temperature should be very smooth. I could figure colorbar out, but could not use it really. Any help is highly appreciated.

Answers (1)

Star Strider
Star Strider on 1 Jun 2016
Try this:
x = linspace(0, 30);
t1 = 20 + 0.5*x;
t2 = 10 + 0.3*x;
c = [t1 flip(t2)];
figure(1)
patch([x flip(x)], [t1 flip(t2)], c, 'FaceColor','interp')
grid
xlabel('Distance (km)')
ylabel('Temperature (°C)')
colormap(jet(100))
<<www-mathworks-com-matlabcentral-answers-uploaded_files-53446-Hi--20I-20have-20shaped-20an-20area-20between-20two-20graphs-20with-20one-20color--20but-20I-20want-20that-20the-20shade-20area-20changes-20the-20color-20with-20rising-20yaxis-20--202016-2006-2001.png>>
  2 Comments
Ha Sen
Ha Sen on 1 Jun 2016
Thanks Star Strider, I tried it, but it did not work. Maybe because both of my graphs are nonlinear? Is there another way?
Star Strider
Star Strider on 2 Jun 2016
My pleasure.
That it ‘did not work’ does not give me any useful information.
It should not make a difference if they are linear or non-linear. I would have to have your data and your code to determine what the problem is.

Community Treasure Hunt

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

Start Hunting!