1
$\begingroup$

I've been stuck on a seemingly simple Graphics issue for quite a while now...

I am trying to make a temperature distribution Plot that will have a colorFunction filling to show red when at a higher temperature, then fading to blue as it gets colder, etc. My plot has temperature in the y-axis, and length (of a fin) in the x-axis.

When I try to put it into effect, the filling is filled with the gradient but it goes from left to right, along the x-axis. However, I want it to be fading top to bottom, to illustrate how the temperature decreases. One of my cells of test code is included below:

    Manipulate[
 Plot[T[x, length, h, P, A, k, Tinf, T0], {x, 0, length},
  ColorFunction -> 
   Function[{x, T}, 
    Directive[
     Opacity[0.7], (ColorData["DeepSeaColors"][Rescale[T, {0, 50}]])]],
  ColorFunctionScaling -> False,
  ImageSize -> 200,
  PlotRange -> {0, T0}, 
  Filling -> Axis,
  PlotStyle -> Thick,
   AxesLabel -> {x, \[Theta]}],

 {{length, 5}, 1, 30, 1, Appearance -> "Labeled"}
 ]

graph of the code

I've tried a lot of convoluted methods like making a customized Raster image for the filling color, but I'm sure there has to be a simpler way to do this!

EDIT:

I want to be able to do this with the Plot function, so it is easier to Manipulate for the user. Right now I was able to get it to work by creating the data separately and then using a ListLinePlot, like so:

heatData = Transpose[{Range[100], Table[-0.5 x + 50, {x, 1, 100}]}];
bands = 50;

ListLinePlot[Table[{1, i} # & /@ heatData, {i, 0`, 1`, 1/bands}], 
 Background -> White, ColorFunction -> "TemperatureMap", 
Filling -> True]

graph of the code

Thank you so much!

$\endgroup$
  • $\begingroup$ Closely related: Can I make a plot with gradient filling?. So in other words, it's not as easy as it should be, unfortunately... $\endgroup$ – Jens Jan 6 '14 at 1:49
  • $\begingroup$ Yup that was the one thread I stumbled upon... I tried that example out and it still ended up showing the colorFunction left-to-right... I guess a ListLinePlot ends up displaying different than a normal Plot? Thanks though! $\endgroup$ – madacho Jan 6 '14 at 1:53
  • $\begingroup$ I have marked this as a duplicate. As written it appears to be one. If you have specific problems with solutions from the prior Q&A, or if you believe you need something different, please describe precisely how your needs differ from the prior question. $\endgroup$ – Mr.Wizard Jan 6 '14 at 2:20
  • $\begingroup$ The code presented doesn't run on 9.0.1 $\endgroup$ – bobthechemist Jan 6 '14 at 2:23
  • $\begingroup$ I don't believe the Plot function has this capability, so the question becomes what is an acceptable substitute? Heike showed how to use ParametricPlot with essentially the same appearance as Plot. Do you understand how to use it? Do you need help writing it as a function e.g. myPlot that automatically fills with a vertical gradient? Do you need a specific feature of Plot that is not present or does not work the same in ParametricPlot? $\endgroup$ – Mr.Wizard Jan 6 '14 at 2:32