2
$\begingroup$

I am trying plot data using a ColorData function to do a gradient of color from blue to red, I used "Rainbow" option, but something is not going well. The color gradients are not following the third variable.

Data example:

tab={{192,35,11},{35,16,31},{50,200,65}}

My code is:

 ListPlot[List /@ Sort[tab[[All, {1, 2}]]], AxesOrigin -> {0, -90},
 PlotRange -> {{0, 360}, {-90, 90}}, Frame -> True, FrameLabel -> {"x", ""},
 Background -> GrayLevel[.01], PlotStyle -> (PointSize[0.03]),
 ColorFunction -> (ColorData["Rainbow"][#/90] & /@ List /@ Tab[[All, 3]]),
 AspectRatio -> 1, PlotLegends -> Placed[BarLegend[{"Rainbow", {10, 75}}, 
 LegendMargins -> {{0, 0}, {10, 5}}, LegendLabel -> "[km/seg]", 
 LegendFunction -> "Panel"], Right], ImageSize -> Large]
$\endgroup$
2
$\begingroup$

In such cases you might want to use Graphics with Blend.

tab = Sort@RandomInteger[100, {20, 3}];

{c1, c2} = MinMax[tab[[All, 3]]]
(*you can define your own minimum or maximum value*)

col[c_] := Blend[{Red, Blue}, (c - c1)/(c2 - c1)]
(*color scaled between 0 and 1. You can choose any combination of colors*)

leg = BarLegend[{{Red, Blue},{c1, c2}},LegendLabel->"[km/seg]",ImageSize -> 200];
(*define the legend*)

Grid[{{Graphics[{{PointSize[Large], col[#[[3]]], Point[#[[1 ;; 2]]]} & /@ tab,
       Line[tab[[All, 1 ;; 2]]] (*Line is optional*)}, 
 Frame -> True, ImageSize -> 200], leg}}] 

enter image description here

$\endgroup$
  • $\begingroup$ Now it is more clear scaling data color as you did . ColorData and ColorFunction are not so easy to understand how implementing them. $\endgroup$ – locometro Jul 9 '17 at 5:17
4
$\begingroup$
tab = {{192, 35, 11}, {35, 16, 31}, {50, 200, 65}};
styledtab = Style[{#, #2}, PointSize[.03], ColorData[{"Rainbow", {10, 75}}][#3]] & @@@ tab;

ListPlot[styledtab, AxesOrigin -> {0, -90}, 
 PlotRange -> {{0, 360}, {-90, 250}}, Frame -> True, 
 FrameLabel -> {"x", ""}, Background -> GrayLevel[.01], AspectRatio -> 1, 
 PlotLegends -> Placed[BarLegend[{"Rainbow", {10, 75}}, 
    LegendMargins -> {{0, 0}, {10, 5}}, LegendLabel -> "[km/seg]", 
    LegendFunction -> "Panel"], Right], ImageSize -> Large]

enter image description here

Update: Perhaps BubbleChart is more convenient to use with ColorFunction

BubbleChart[tab, BubbleSizes -> {0.07, .07}, 
 ColorFunction -> (ColorData[{"Rainbow", {10, 75}}][#3] &), 
 ColorFunctionScaling -> False, AxesOrigin -> {0, -90}, 
 PlotRange -> {{0, 360}, {-90, 250}}, Frame -> True, 
 FrameLabel -> {"x", ""}, Background -> GrayLevel[.01], 
 AspectRatio -> 1, ImageSize -> Medium]

enter image description here

$\endgroup$
  • $\begingroup$ With the black background the frame-axes are hidden (it also looks nice with a white background, +1 anyway) $\endgroup$ – eldo Jul 7 '17 at 13:26

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.