2

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?

Harry
  • 2,715
  • 14
  • 27

1 Answers1

4

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

N.J.Evans
  • 5,093
  • 19
  • 25