2
$\begingroup$

I read lot of questions about this issue, mainly: the stack code

So,I tried create a list plot with bar legend , using the following code:

    ListPlot[List /@ rad[[All, 1 ;; 2]], AxesOrigin -> {0, -90}, 
 DataRange -> {{0, 360}, {-90, 90}}, Frame -> True, 
 BaseStyle -> {FontFamily -> "Kartika", 12}, 
 FrameLabel -> {"RA (\[Degree])", "DEC (\[Degree])"}, 
 PlotStyle -> ({PointSize[0.002], ColorData["Rainbow"][#/85]} & /@ 
    rad[[All, 3]]), AspectRatio -> 1, 
 PlotLegends -> 
  Placed[BarLegend[{"Rainbow"}, LegendMargins -> {{0, 0}, {10, 5}}, 
    LegendLabel -> "Geocentric Velocity [km/seg]", 
    LegendFunction -> "Panel", 
    LabelStyle -> {Italic, FontFamily -> "Helvetica"}], Above]]

using the data:

a = RandomReal[360, {1000}];
b = RandomReal[90, {1000}];
c = RandomReal[90, {1000}];
rad = Transpose[{a, b, c}];

It worked fine, but the legendbar did not , it just does not appear, only the plotting.

What did I do wrong?

EDIT 1:

The new code with some suggested modifications:

 ListPlot[List /@ rad[[All, 1 ;; 2]], AxesOrigin -> {0, -90}, 
     DataRange -> {{0, 360}, {-90, 90}}, Frame -> True,  
     FrameLabel -> {"RA (\[Degree])", "DEC (\[Degree])"}, 
     PlotStyle -> ({PointSize[0.002], ColorData["Rainbow"][#/85]} & /@ 
        rad[[All, 3]]), AspectRatio -> 1, 
     PlotLegends -> 
      Placed[BarLegend["Rainbow", LegendMargins -> {{0, 0}, {10, 5}}, 
        LegendLabel -> "Geocentric Velocity [km/seg]", 
        LegendFunction -> "Panel"] Above]]

The resulting plot:

I used the actually data, more than 3.500 points with also negative declinations points (I preferred not using them in this question, as the final LegendBar would be the same using the sample of random data).

The plotting

And a complement question:

why is the range in bar not 0 -> 90.0?

$\endgroup$
4
  • $\begingroup$ Could you attach the actual plot you obtain? Thanks. $\endgroup$
    – bbgodfrey
    Jan 23, 2015 at 19:37
  • 1
    $\begingroup$ Please pare your code down to the minimal example that illustrates your problem. You don't need FontFamily -> "Kartika" for example. This will help us help you. $\endgroup$ Jan 23, 2015 at 19:56
  • $\begingroup$ Oh sorry, I will do this $\endgroup$
    – locometro
    Jan 23, 2015 at 20:12
  • 1
    $\begingroup$ The range is {0,90} now. I made the edit when I saw your earlier Comment, which now appears to be gone. $\endgroup$
    – bbgodfrey
    Jan 23, 2015 at 20:37

1 Answer 1

2
$\begingroup$

The fix is a simple one. Replace {"Rainbow"} by {"Rainbow", {0, 90}} to produce

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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