2
$\begingroup$

Because of the problem described in BarLegend can't make spaced contours when contours number>11, I decided to brew my homemade spaced-contours-barlegend. After some trials I get something like this(combined with Row[{plapla, code-below}]):

ContourPlot[y, {x, 0, .2}, {y, 0, 1}, ColorFunctionScaling -> False, 
ColorFunction -> (Blend[{Purple, Blue, Green, Orange, Red, 
  Red}, #] &), Contours -> 17, PlotRangePadding -> 0, 
Frame -> True, Axes -> False, 
FrameTicks -> {{None, {#, 180*# + 60, {0, 0.6}} & /@ 
 Range[0, 1, 2/18]}, {None, None}}, 
FrameTicksStyle -> Directive[Thick, 20], 
FrameStyle -> Directive[Thick], AspectRatio -> 16, ImageSize -> 80]

which produce:

enter image description here

It looks OK at a glance, but I noticed that there is slightly disalignment between the contours and the frame ticks. Why is this happening? How can I avoid it?

$\endgroup$
  • 2
    $\begingroup$ Use Contours -> Range[0, 1, 1/18] to force equal spacing. $\endgroup$ – Bob Hanlon Jun 15 '15 at 14:47
  • $\begingroup$ Note that Length[Range[0, 1, 2/18]] is $\ne 17+2$, so therein lies your mismatch. $\endgroup$ – J. M.'s technical difficulties Jun 15 '15 at 19:15
4
$\begingroup$

Instead of providing the number of contours you want with the option Contours you should provide the values at which you want contours. When using this with a contour plot that uses the same color scheme, you should provide the same values for contours to the contour plot, or you may end up with a mismatch between your legend and the plot.

ContourPlot[y, {x, 0, .2}, {y, 0, 1}
 , ColorFunctionScaling -> False
 , ColorFunction -> (Blend[{Purple, Blue, Green, Orange, Red, 
      Red}, #] &)
 , Contours -> Range[0, 1, 1/18]
 , PlotRangePadding -> 0
 , Frame -> True
 , Axes -> False
 , FrameTicks -> {{None, {#, 180*# + 60, {0, 0.6}} & /@ 
     Range[0, 1, 2/18]}, {None, None}}
 , FrameTicksStyle -> Directive[Thick, 20], 
 FrameStyle -> Directive[Thick]
 , AspectRatio -> 16, ImageSize -> 80
 ]

Gives:

enter image description here

| improve this answer | |
$\endgroup$

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.