3
$\begingroup$

I have a list contour plot overlay by a 15x15 mesh grid. And I want to label the axes with numbers positioned at the center of the cells instead of the grid lines.

 data = {
 {1, 0, 2, 3, 4, 5, 6, 6, 7, 8, 8, 8, 8, 8, 8},
 {0, 0, 2, 3, 4, 4, 5, 6, 7, 7, 9, 9, 9, 9, 8},
 {0, 1, 2, 3, 4, 4, 5, 6, 6, 8, 9, 9, 9, 8, 9},
 {0, 2, 3, 4, 5, 6, 6, 6, 7, 8, 8, 9, 9, 8, 8},
 {0, 2, 3, 4, 5, 6, 7, 7, 8, 8, 9, 9, 9, 8, 7},
 {1, 2, 2, 4, 5, 6, 6, 7, 8, 8, 8, 8, 9, 8, 8},
 {1, 2, 4, 4, 5, 6, 6, 7, 7, 8, 8, 9, 9, 8, 8},
 {1, 2, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 8, 8, 8},
 {2, 2, 3, 3, 4, 5, 6, 7, 9, 8, 8, 8, 8, 8, 7},
 {2, 2, 3, 3, 4, 5, 6, 7, 8, 8, 7, 7, 8, 7, 7},
 {1, 1, 1, 2, 4, 4, 6, 7, 8, 7, 7, 6, 6, 6, 7},
 {0, 1, 1, 2, 3, 4, 5, 7, 7, 7, 7, 6, 5, 5, 6},
 {0, 1, 2, 3, 4, 5, 6, 7, 5, 5, 6, 6, 5, 5, 5},
 {1, 2, 2, 2, 4, 4, 5, 6, 6, 4, 5, 6, 5, 5, 4},
 {3, 3, 3, 3, 3, 4, 6, 6, 7, 4, 4, 5, 5, 4, 2}};

ListContourPlot[
data, ColorFunction -> ColorData[{"Warm", "Reverse"}],
ContourLabels -> None, ContourStyle -> None, InterpolationOrder -> 4, 
Contours -> 10, Mesh -> 14,  MeshFunctions -> {#1 &, #2 &}, 
MeshStyle -> Black, ScalingFunctions -> {Identity, "Reverse"}, 
FrameTicks -> {{Table[{-i - 0.5, i}, {i, 0, 14, 1}], None}, {None, Table[{i + 0.5, i}, {i, 0, 14, 1}]}}]

enter image description here

However, the frame ticks doesn't fit to the grids completely. Is there any way to fix it?

$\endgroup$
  • 2
    $\begingroup$ Mesh->{Range[14]-0.5,-(Range[14]+0.5)} will line put mesh exactly on your ticks. Drop the 0.5 if you want the mesh shifted a half cell relative to the ticks. $\endgroup$ – N.J.Evans Aug 30 '17 at 17:56
  • $\begingroup$ I tried your methods, the ticks fit perfectly with the mesh. But the mesh become 14x14 instead of 15x15. I want it to be 15x15 because I want to assign coordinates for each of the elements in data. $\endgroup$ – Kent Vk Aug 30 '17 at 18:14
  • $\begingroup$ To modify @N.J.Evans comment, try it with either Mesh -> {Range[15] - 0.5, -(Range[15] + 0.5)} or Mesh -> {Range[15], -Range[15]}. Are they what you're looking for? $\endgroup$ – aardvark2012 Aug 31 '17 at 3:43
  • $\begingroup$ No, I want 15x15 equal sized grids, with ticks labeled at the center to the cells. Changing Mesh->{Range[14]-0.5,-(Range[14]+0.5)}, Mesh->{Range[14],-(Range[14])}, Mesh->{Range[15]-0.5,-(Range[15]+0.5)} or Mesh->{Range[15],-(Range[15])} doesn't give 15x15 equal sized cells and the ticks labeled from 1 to 15. $\endgroup$ – Kent Vk Aug 31 '17 at 14:02
1
$\begingroup$

I found what I want by modifying the frame ticks.

FrameTicks -> {{Table[{-(22/15) - 14/15 (i - 1), i}, {i, 1, 15, 1}], 
None}, {None, Table[{22/15 + 14/15 (i - 1), i}, {i, 1, 15, 1}]}}

The total width of a row is 14 units. By splitting it into 15 equal size cells each segment will have $14/15$ units and half of a unit is $7/15$ units. So the tick label 1 is in position $1+7/15=22/15$, label 2in position $(22/15)+14/15$, label 3 in position $(22/15)+14/15+14/15$ and this eventually forms an arithmetic progression.

$\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.