1
$\begingroup$

I am using the following code to generate a density plot using a data file (which has three columns). The first column is X axis and second column is Y axis and the third column is the color. It gives me a plot with different color points.

ListPlot[Table[
  Style[{AvsCvsThetaData[[i, {1, 2}]]}, 
   Hue[AvsCvsThetaData[[i, 3]]/(Pi)]], {i, Length[AvsCvsThetaData]}], 
 PlotStyle -> PointSize[Medium], Frame -> {True, True, True, True}, 
 FrameTicks -> Automatic, FrameLabel -> {"A", "C"}, 
 LabelStyle -> 
  Directive[Black, Bold, Medium, FontFamily -> "Helvetica"], 
 RotateLabel -> False, PlotRange -> Full]

Now suppose, instead of the points, I want a line connecting all the points and the color of the line should change according to the 3rd column. I don't really know whether it is possible to do or not. Can anyone suggest something!

$\endgroup$
  • $\begingroup$ Can you add a little of the data so we know what you're working with? You probably want to check out ListLinePlot and ColorFunction. $\endgroup$ – Carl Lange Jan 21 at 15:38
  • $\begingroup$ do you want to color the line based on (the third coordinate of) the first point or do you prefer to blend the colors of the two end points of the a line? $\endgroup$ – kglr Jan 21 at 15:39
  • $\begingroup$ @CarlLange: ListLinePlot does not work here. My data file has the numerical values of a function $f(x,y,z)$. I don't know the functional form of the function otherwise I could have used ParametricPlot. $\endgroup$ – Parveen Jan 21 at 15:47
  • $\begingroup$ @kglr: As I have different color for different point (based on the value of 3rd coordinate at that point), I want to connect those two point using a linear interpolation and then color can go accordingly. $\endgroup$ – Parveen Jan 21 at 15:49
  • 1
    $\begingroup$ Please do not use tags unrelated to the problem that are you asking about (is this problem specific to Mathematica Online?) $\endgroup$ – Szabolcs Jan 21 at 15:55
2
$\begingroup$
SeedRandom[123]
data = Join[RandomReal[10, {100, 2}], List /@ RandomReal[{0, Pi}, 100], 2];

ListPlot[Table[Style[{data[[i, {1, 2}]]}, Hue[data[[i, 3]]/(Pi)]], {i, 
   Length[data]}], PlotStyle -> PointSize[Medium], 
 Frame -> {True, True, True, True}, FrameTicks -> Automatic, 
 FrameLabel -> {"A", "C"}, 
 LabelStyle -> Directive[Black, Bold, Medium, FontFamily -> "Helvetica"], 
 RotateLabel -> False, PlotRange -> Full]

enter image description here

One possible way is to use Graphics:

Graphics[{Hue[#[[3]]/Pi], PointSize[Large], Point[#[[;; 2]]]} & /@ data, 
 Frame -> True, FrameLabel -> {"A", "C"}, 
 LabelStyle -> Directive[Black, Bold, Medium, FontFamily -> "Helvetica"], 
 RotateLabel -> False, AspectRatio -> 1/GoldenRatio]

enter image description here

To color each line base on the color of its first point:

Graphics[{Hue[#[[1, 3]]/Pi], Thick, Line[#[[All, ;; 2]]]} & /@ Partition[data, 2, 1], 
 Frame -> True, FrameLabel -> {"A", "C"}, 
 LabelStyle -> Directive[Black, Bold, Medium, FontFamily -> "Helvetica"], 
 RotateLabel -> False, AspectRatio -> 1/GoldenRatio]

enter image description here

To color each line by blending the colors of its endpoints:

Graphics[{Thick, Line[data[[All, ;; 2]], VertexColors -> (Hue /@ (data[[All, 3]]/Pi))]},
 Frame -> True, FrameLabel -> {"A", "C"}, 
 LabelStyle -> Directive[Black, Bold, Medium, FontFamily -> "Helvetica"], 
 RotateLabel -> False, AspectRatio -> 1/GoldenRatio]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks dude. I must admit you are excellent in using mathematica. $\endgroup$ – Parveen Jan 21 at 16:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.