# How to find peaks in List contour plot figure

Mat = {{4, 1125, 4348, 4524, 2906, 1989, 1237, 1524, 1427, 1272, 483,
82, 19, 1, 0, 0}, {3, 358, 4182, 7850, 5324, 4121, 3061, 2688,
1293, 1937, 120, 107, 6, 3, 4, 6}, {0, 0, 157, 379, 26, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 3, 108, 173, 117, 36, 4, 0, 0, 0,
0, 0, 0, 0, 0}, {0, 0, 0, 0, 37, 111, 74, 30, 29, 29, 36, 48, 32,
6, 3, 1}, {0, 0, 0, 0, 285, 159, 154, 0, 0, 0, 0, 0, 0, 0, 0,
0}, {0, 0, 0, 89, 139, 83, 16, 12, 27, 1, 0, 0, 0, 0, 0, 0}, {0,
0, 47, 254, 50, 13, 24, 63, 12, 4, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0,
3, 47, 170, 95, 84, 7, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 18, 180, 85,
94, 196, 23, 0, 0, 0, 0, 0, 0, 0}};

x = {1/5, 2/5, 3/5, 4/5, 1, 6/5, 7/5, 8/5, 9/5, 2};

y = {200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800,
850, 900, 950};

data3 = Flatten /@Flatten[Transpose[{Outer[List, x, y], Mat}, {3, 2, 1}], 1];

ListContourPlot[MapAt[Log, data3, {All, ;; 1}], PlotRange -> All,
Contours -> 10, InterpolationOrder -> 3,
PlotLegends -> Placed[Automatic, Right], ImageSize -> 400,
AspectRatio -> 1/GoldenRatio, ColorFunction -> {"DarkTerrain"},
FrameTicks -> {{{300, 500, 700, 900, 1000},
ChartingScaledFrameTicks[{Log,
Exp}]}, {ChartingScaledTicks[{Log, Exp}],
ChartingScaledFrameTicks[{Log, Exp}]}}]


I want to plot line through the maxima points in the list contour plot figure

• I'm not sure I know what you mean - I see just one peak in the figure. Do you want to draw a line from top to bottom tracing the maximum of each row, or a line from left to right tracing the maximum of each column? Dec 2, 2015 at 15:41
• line show the peaks through contours relative to the value of x axis Dec 2, 2015 at 16:00
• Don't the peaks lie on a contour? Dec 2, 2015 at 21:17

You can find a max line going horizontally or vertically. The point of the obtuse code below is to first find the max value for each row of Mat, then find the position of that value in data4 and extract the first two elements associated with that value. Then you have to sort so that your line doesn't zigzag.

maxVline =
Sort[Extract[data4,
ReplacePart[Position[data4, Max[#]], {1, 2} -> {1, 2}]][[1]] & /@
Transpose@Mat, #1[[2]] < #2[[2]] &]
maxHline =
Sort[Extract[data4,
ReplacePart[Position[data4, Max[#]], {1, 2} -> {1, 2}]][[1]] & /@
Mat, #1[[1]] < #2[[1]] &]
(* {{-Log[5], 200}, {-Log[5], 200}, {-Log[5], 250}, {-Log[5],
300}, {-Log[5/2], 350}, {-Log[5/2], 400}, {-Log[5/2],
450}, {-Log[5/2], 500}, {-Log[5/2], 550}, {-Log[5],
600}, {-Log[5/2], 650}, {-Log[5], 700}, {-Log[5/2],
750}, {-Log[5/2], 800}, {-Log[5/2], 800}, {0, 800}} *)
(* {{-Log[5], 350}, {-Log[5/2], 350}, {-Log[5/3],
350}, {-Log[5/4], 400}, {0, 450}, {Log[6/5], 400}, {Log[7/5],
400}, {Log[8/5], 350}, {Log[9/5], 500}, {Log[2], 550}} *)


Now you can use Show to combine the contour plot with a line plot,

ctplot = ListContourPlot[data4, PlotRange -> All,
Contours -> 10,(*InterpolationOrder\[Rule]3,*)
PlotLegends -> Placed[Automatic, Right], ImageSize -> 400,
AspectRatio -> 1/GoldenRatio, ColorFunction -> {"DarkTerrain"},
FrameTicks -> {{{300, 500, 700, 900, 1000},
ChartingScaled +
FrameTicks[{Log, Exp}]}, {ChartingScaledTicks[{Log, Exp}],
ChartingScaledFrameTicks[{Log, Exp}]}}];
Show[ctplot, ListLinePlot[maxVline, PlotStyle -> {Thick, Red, Dashed}]]
Show[ctplot,
ListLinePlot[maxHline, PlotStyle -> {Thick, Red, Dashed}]]


• Glad to help! If that solves your problem go ahead and click the checkmark next to the answer so it doesn't show up in the "Unanswered Questions" list (there's also an up arrow there :-) Dec 2, 2015 at 16:36