Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

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 vue (au cours des 30 derniers jours)
Ha Sen
Ha Sen le 1 Juin 2016
Clôturé : MATLAB Answer Bot le 20 Août 2021
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.

Réponses (1)

Star Strider
Star Strider le 1 Juin 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 commentaires
Ha Sen
Ha Sen le 1 Juin 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 le 2 Juin 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.

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by