Using Map inside Plot to show multiple curves?

Hi.

I am attempting to plot a series of moisture saturation curves (relative humidity) versus dry-bulb temperature, and label them (e.g., 10%, 20%, etc.). There are ten lines to be plotted, so I wrap the Plot function around a Map to generate each line. When I do this only the first (RH = 10%) line gets labeled (see attached notebook). However, when I explicitly Plot the output of the Map all lines get labeled. Can anyone explain this behavior? From what I see, both expressions are equivalent (obviously not!), and should produce identical output. What am I missing?

What’s different if I explicitly plot the results of the Map function
versus evaluating the Map inside the Plot?

Attributes@Plot
(* {HoldAll, Protected, ReadProtected} *)

The difference is caused by the HoldAll attribute. Try this

Plot[Evaluate[# saturatedMoistureContent[t] & /@ Range[0.1, 1, 0.1]], {t, 0, 50}, 
 PlotLabels -> {"10%", "20%", "30%", "40%", "50%", "60%", "70%", 
   "80%", "90%", "100%"}]

If you want all the lines to have the default color, add

PlotStyle -> ColorData[97][1]

The reason for this behavior is that Plot[] has the attribute HoldAll, i.e. basically its arguments stay in an unevaluated form. Consequently you can/should write (for your specific case):

Plot[Evaluate[# saturatedMoistureContent[t] & /@ Range[0.1, 1, 0.1]], 
{t, 0, 50}, PlotLabels -> {"10%", "20%", "30%", "40%", "50%", "60%", "70%", 
   "80%", "90%", "100%"}]

or likewise:

Plot @@ {# saturatedMoistureContent[t] & /@ Range[0.1, 1, 0.1], {t, 0, 50}, PlotLabels -> {"10%", "20%", "30%", "40%", "50%", "60%", 
    "70%", "80%", "90%", "100%"}}

Hi Rohit, sorry, I did not see your response in time … Regards – Henrik

Thanks to you both! That was exactly what I needed. :slight_smile:

Rohit, in another version of the notebook I used PlotStyle->Blue for that purpose. Thanks for thinking ahead on that.

Hi Henrik,

No worries. I have done the same in the past. Sometimes there is a significant lag between when an answer is posted and when it appears on the site.