0
$\begingroup$

This question already has an answer here:

I have a huge list of data in the form of triplets numbers (e.g. {x,y,z}) and I want 2d plot. In which I want to plot y vs x on which values of z should be shown with color depending on the value of z for each x,y point. Means variation of z with color on x,y plot. Is it possible to show plot legend outside the plot boundaries?

Please give me suggestions

$\endgroup$

marked as duplicate by Sjoerd C. de Vries, m_goldberg, Jens, Artes, halirutan Jul 3 '13 at 23:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    $\begingroup$ Some suggestions: ListDensityPlot, ListPlot, Graphics/Point $\endgroup$ – Kuba Jul 3 '13 at 12:44
2
$\begingroup$

The Simplest way is to use Graphics and put the points.

dat = Table[{x, Sin[x], Cos[x]}, {x, 0., 4 \[Pi], \[Pi]/10.}]; (*trial data set*)
(*column 1 and 2 is for data and 3 is for colour*)

ndata = Length[dat];
min = Min[dat[[All, 3]]];max = Max[dat[[All, 3]]];
col = (dat[[All, 3]] - min)/(max - min);
(*to scale the colour index between 0 and 1*)

Graphics[Table[{ColorData["NeonColors"][col[[i]]], PointSize -> Large,
Point[{dat[[i, 1]], dat[[i, 2]]}]}, {i, 1, ndata}], Axes -> True, AspectRatio -> .5]

Simplified Version [courtesy Anon and belisarius]

col = Rescale[dat[[All, 3]]]; pts = dat[[All, 1 ;; 2]];
Graphics[Table[{ColorData["NeonColors"][col[[i]]], PointSize -> Large,
Point[pts[[i]]]}, {i, ndata}], Axes -> True, AspectRatio -> .5]

For drawing with Line

Graphics[Table[{ColorData["NeonColors"][col[[i]]], Thick,
Line[{pts[[i]], pts[[i + 1]]}]}, {i, ndata - 1}], Axes -> True, AspectRatio -> .5]

color plot

Using ColorScheme as legend

Needs["PlotLegends`"]
(*create legendbox*)
legend = Graphics[Legend[ColorData["NeonColors"][1 - #1] &, 10, " Max", " Min", 
LegendShadow -> None, LegendBorder -> Automatic]];

(*put it in inset*)
lps = {11.0, .5}; (*legend position*)
Graphics[{Table[{ColorData["NeonColors"][col[[i]]], Thick, 
Line[{pts[[i]], pts[[i + 1]]}]}, {i, ndata - 1}], 
Inset[legend, lps, Automatic, {1, 1}]},
Axes -> True, AspectRatio -> .5, ImageSize -> 500]

legend

$\endgroup$
  • 1
    $\begingroup$ Take a look at Rescale[] $\endgroup$ – Dr. belisarius Jul 3 '13 at 18:29
  • 1
    $\begingroup$ I was just about to say that, (1) col = Rescale[dat[[All, 3]]];, (2) pts = dat[[All, 1 ;; 2]]; simplifies the Point to Point[pts[[i]]] and (3) {i, 1, ndata} is equivalent to {i,ndata}. But nice answer, +1. $\endgroup$ – C. E. Jul 3 '13 at 18:32
  • $\begingroup$ Thanks for suggestions but if i want join all my points then how can i include this in your given code $\endgroup$ – physicist Jul 4 '13 at 19:10
  • $\begingroup$ well @physicist, then you can chose two points at a time and use Line. $\endgroup$ – Sumit Jul 4 '13 at 20:55
  • $\begingroup$ How can i reverse the order of colors in this scheme in the code $\endgroup$ – physicist Jul 11 '13 at 7:57

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