Create a color gradient using a variable?

Let say I have a function

F[x_,y_]:=x^2+6y^(3/2)

Now I want to plot a 2D plot of F[ ] vs x, and need to use y variable as a color gradient. Here I want to vary y as a color axis and the values of F will be plotted against x it will be like this


but with different function

Hi John,

Not clear what you are asking for. Maybe ContourPlot or DensityPlot?

ContourPlot[f[x, y], {x, -10, 10}, {y, 0, 10},
 Contours -> 10,
 ContourLabels -> All,
 ColorFunction -> "Rainbow",
 PlotRangePadding -> Scaled[.04]]

DensityPlot[f[x, y], {x, -10, 10}, {y, 0, 10},
 ColorFunction -> "Rainbow"]

I need this type of plot having y as the color variable

Cross posted: https://mathematica.stackexchange.com/q/231010/1871

Like this? I think you will have to adapt the Hue-expression

Plot[
 Cos[x] Exp[- .1 x^2], {x, -5, 5},
 PlotStyle -> Thick,
 ColorFunction -> Function[{x, y}, Hue[ y]]
 ]

Or this?

F[x_, y_] := x^2 + 6 y^(3/2)

Plot3D[F[x, y], {x, -3, 3}, {y, 0, 4}, ColorFunction -> Function[{x, y, z}, Hue[y]] ]

I still don’t understand the question? What are you asking for? Kind of lost here.

I am now explaining the problem with more detailed way, Let’s consider

F[x_,y_]:=Sqrt[ (5*10^-6)*x^2*(5*10^-9)^y]
y=Sqrt[Tan[x]]

Now I have to randomly vary x to some range and make it the color bar axis and the values for F[x,y] and y for each x are plotted in y vs F[x,y]

???

What do you want to do?

Perhaps you can give a handmade example?

v = 246
E1 = 9000

PT = ((Subscript[E1, T]*v)/(
   Subscript[v, n]*E1))/((Subscript[v, n]/Subscript[T, n])^-1*(v/
    E1)) - 7*(Log[Subscript[v, n]]/Subscript[T, n]) + 
  Log[Subscript[T, n]/100]
Subscript[v, n]/Subscript[T, n] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
Subscript[T, n] = {300, 500, 469, 650, 546, 389, 456, 411, 523, 700};
((Subscript[E1, T]*v)/(Subscript[v, n]*E1)) = 
 RandomReal[{1, 3.1}, {10}]

Now I have to randomly vary the last ratio to some range and make it the color bar axis and the values for PT and v_n/T_n for each ratios can be plotted PT vs v_n/T_n plot making the ratio as color axis

OK. But you are merely repeating your words. For me it is not all all clear what you want to do. And: I suggest that you eliminate all these subscript-expressions. They may be a reason for a lot of mistakes

Hi John,

your code gives error messages because of synthax.mistakes. I had a close look at it and concluded that you want to calculate PT and do it like this

v = 246
E1 = 9000

Tn = {300, 500, 469, 650, 546, 389, 456, 411, 523, 700}
vn = Range[10] Tn
E1T = E1 vn RandomReal[{1, 3.1}, 10]/ v
PT = E1T/Tn - 7 Log[vn]/Tn + Log[Tn/100]

Is this right?

But a Plot doesn’t look like yours

ListLinePlot[Transpose[{vn/Tn, PT}]]

Any comments?

v = 246
E1 = 9000

PT = ((ET*v)/(
   vn*E1))/((vn/Tn)^-1*(v/
    E1)) - 7*(Log[vn]/Tn) + 
  Log[Tn/100];
vn/Tn= {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
Tn= {300, 500, 469, 650, 546, 389, 456, 411, 523, 700};
((ET*v)/(vn*E1)) := 
 RandomReal[{1, 3.1}, {10}];

Now I have to plot between (vn/Tn) vs PT making a variable color axis of ((ET*v)/(vn*E1)) as like the attatched graphics( it should look like a set of data points but having varing colors depending on ((ET*v)/(vn*E1))) , The plot may not exactly look like it since I have putted some mannual data by hand

Hi John,

didn’t you understand? Your code is WRONG, Have you ever run it? I tried to fix the flaws and asked you if you agree to the results of the new version. But you did not answer to that question. So: please check it.

Then ((ETv)/(vnE1)) is the array of the random numbers. Check this too.

After that we can talk about colors.

Here is a 1st attempt

v = 246
E1 = 9000

Tn = {300, 500, 469, 650, 546, 389, 456, 411, 523, 700}
vn = Range[10] Tn
sumpt = Table[0, {10}]
nn = 1000
Do[
 rr = RandomReal[{1, 3.1}, 10];
 E1T = E1 vn rr/ v;
 PT = E1T/Tn - 7 Log[vn]/Tn + Log[Tn/100];
 sumpt = sumpt + PT,
 {nn}]
sumpt = sumpt/nn
col = Table[1 + (j - 1) 2.1/9, {j, 1, 10}]
ListLinePlot[
 Transpose[{vn/Tn, PT}],
 PlotStyle -> Thick,
 ColorFunction -> Function[{x, y}, Hue[col[[x]]]],
 ColorFunctionScaling -> False
 ]

Thanks for giving your valueable time, I think now it is exactly what I needed, but how to assign the correct color axis, and also guide me how to draw the color line in case of log color data(i.e. a log color axis)

Also I have failed to understand what is the meaning of this part

Do[
 rr = RandomReal[{1, 3.1}, 10];
 E1T = E1 vn rr/ v;
 PT = E1T/Tn - 7 Log[vn]/Tn + Log[Tn/100];
 sumpt = sumpt + PT,
 {nn}]
sumpt = sumpt/nn
col = Table[1 + (j - 1) 2.1/9, {j, 1, 10}]

What do you mean by " the correct color axis " ? The colors are coded accroding to the random number used in the calculation fpr the point in question , your ((ETv)/(vnE1)) .

This is the calculation of averages. The code for PT is executed nn times, the results are added and finally divided by nn. I have no idea whether you wanted such a thing. col is the range of colors.

There in the posted image there is a color axis corresponding to the ratio, It is important since it makes the graphics more detailed, the color axis shown in above figure shows how the colors corresponding to each points related to the values of ((ET*v)/(vn*E1))

Secondly, I only want simply the values of PT (for each random number i.e. one point for each set of data, don’t need any avg like thing) plotted against vn/Tn

Ok. State now is: you have all the hints that you should be able to do what you want.