1

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 y, 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

F vs x

but with different function.

The question was asked several day ago in Wolfram Community but I not got any fruitful answer.

xzczd
  • 65,995
  • 9
  • 163
  • 468
John Wick
  • 73
  • 5
  • F[] is a function of x and y, how can one create "a 2D plot of F[ ] vs x"? – xzczd Sep 30 '20 at 06:01
  • One can also vary y but in the color axis i.e. thiss plot is the 2D projection of the F(x,y) vs x vs y 3D plot – John Wick Sep 30 '20 at 06:03
  • If it's a 2D projection, shouldn't it be a region like ParametricPlot[{x, x^2 + 6 y^(3/2)}, {x, -4, 4}, {y, -1, 1}]? Or you just want to plot at a certain y==a and use the deriative at y==a for coloring? – xzczd Sep 30 '20 at 06:09
  • Thanks I think your first suggestion about basic parametricplot is correct, but how to show the y as color gradient – John Wick Sep 30 '20 at 06:20
  • Something like this?: ParametricPlot[{x, x^2 + 6 y^(3/2)}, {x, -4, 4}, {y, -1, 1}, ColorFunction -> Function[{xaxis, yaxis, x, y}, ColorData["Rainbow"][y]], AspectRatio -> 1/GoldenRatio] – xzczd Sep 30 '20 at 06:26
  • That is perfect!, But a color axis will make it more detailed – John Wick Sep 30 '20 at 06:30

1 Answers1

0

Try this:

{yL, yR} = {-1, 1}; colorfunc = "Rainbow"; 
ParametricPlot[{x, x^2 + 6 y^(3/2)}, {x, -4, 4}, {y, yL, yR}, 
 ColorFunction -> Function[{xaxis, yaxis, x, y}, ColorData[colorfunc][y]], 
 AspectRatio -> 1/GoldenRatio, PlotLegends -> BarLegend[{colorfunc, {yL, yR}}]]

enter image description here

Do notice this visualization won't work well on those functions oscillating in y direction.

xzczd
  • 65,995
  • 9
  • 163
  • 468
  • Sorry i think i have forgotted to log scale one axis – John Wick Sep 30 '20 at 06:52
  • Can you please tell me how to plot this for the case of x and y log axis – John Wick Sep 30 '20 at 07:00
  • @JohnWick Then how will you handle the plot in y<=0 range? – xzczd Sep 30 '20 at 07:09
  • In my case y<=0 is not needed, and also I am facing a issue in merging a list plot with same plotrange with this parametric plot – John Wick Sep 30 '20 at 07:15
  • @JohnWick Do you need to rescale y axis or both x and y axis? – xzczd Sep 30 '20 at 08:15
  • I need to rescale y and F[x,y] by logarithmic scale – John Wick Sep 30 '20 at 08:40
  • @J {yL, yR} = {1,5};colorfunc="Rainbow";ParametricPlot[{x,x^2 + 6 y^(3/2)}/.y->Exp@y//Evaluate,{x,1,4},{y,Log@yL,Log@yR},PlotRange -> All,ColorFunction->Function[{xaxis, yaxis, x, y},ColorData[colorfunc][y]],AspectRatio-> 1/GoldenRatio, ScalingFunctions -> {Automatic, "Log"}, PlotLegends -> BarLegend[{colorfunc, Log@{yL, yR}}, Ticks -> {#, N@Exp@#}\[Transpose] &@{Log@yL, Log@{yL, yR} // Mean, Log@yR}]] The Ticks option in BarLegend is undocumented, check this post for some discussion, ScalingFunctions is red, but don't worry. – xzczd Sep 30 '20 at 08:46
  • Actually I am trying to reproduce the plots of https://arxiv.org/abs/1910.00234 paper, i.e. fig.1 or 2, since all of the plots are done with similar procedure – John Wick Oct 01 '20 at 07:19
  • Now I have asked the question in https://mathematica.stackexchange.com/q/231171/74929 – John Wick Oct 03 '20 at 20:25