Q: Extract ColorRange of ContourPlot I would like to extract the range values Mathematica is assigning colours to in a ListContourPlot (without the range affected by clipping), in order to build custom BarLegends with MaTeX.
I came across this question:
ShowLegend values,
but since this was already more than 5 years ago, I thought somebody might have a better idea? The function provided in the answer seemingly does not work without modifying in Mathematica 11.3.
Ideas?
Edit
Sorry for not providing an example. Let's look at this plot for instance:
SeedRandom[1234]
data = Function[row, 
Append[row, RandomReal[{95, 105}]]] /@ (Flatten[
Table[{i, j}, {i, 1, 3}, {j, 1, 3}], 1]);
data[[1, 3]] = 1;
ListContourPlot[data, PlotLegends -> Automatic]

Which gives

How can I now find out where Mathematica begins to assign the ColorFunction? Clearly, the value 1 in data[[1,3]] is clipping and therefore not part of the scale. In order to exactly rebuild such a BarLegend, I need the maximum and minimum values for it.
Edit 2
What I finally want, is to rebuild the original legend like so
BarLegend[{ColorData["M10DefaultDensityGradient"], {86, 106}}, 9, 
"Ticks" -> Range[88, 104, 2], LegendLabel -> "DIY BarLegend", 
ColorFunctionScaling -> True]


without having to "guess" the range for the colours (in this case {86,106}) but get them via code, to avoid incorrect Ticks. Because of the clipping, these values won't just be the minimum and maximum of the data anymore, so I'm interested in where Mathematica is clipping.

A: If I understand correctly, you'd like to get the RGB values for each of the 10 color swatches in the legend.  If so, here's one way to do it.  It requires that the ContourPlot has already been created and stored in a symbol.  I used your code and o = ListContourPlot[data, PlotLegends -> Automatic].
Clear[legendExtract];
Options[legendExtract] = {"RGBasReal" -> False};
legendExtract[plot_Legended, OptionsPattern[]] := Module[
  {legend = plot[[2, 1]], colordata, range, out},
  (* Extract colorfunction used in plot and the range of values used in the color scaling *)
  {colordata, range} = legend[[1]] /. {b_Blend & :> b[[1]]};
  (* Create list of values and colors used in legend *)
  out = {#, ColorData[colordata][Rescale[#, range]]} & /@ 
     legend[[2]] /. {{y_Real, _} :> y};
  (* If desired, output RGB values as real numbers instead of swatches *)
  If[OptionValue["RGBasReal"] == True, 
   out /. {RGBColor[vals__] :> vals}, out]
  ]

It has not be thoroughly tested, but seems to work for your test case:

