3
$\begingroup$

I have a dataset and would not want Mathematica to interpolate at all while plotting the contours. This is because the data contains essential binning information and the "steps" in the contour must convey that sense. Interpolating on the data to "smoothen" the contours would make the plot lose its physical validity altogether. Apparently, ListContourPlot doesn't show the contour lines at all when InterpolationOrder is set to 0.

ListContourPlot[data, ScalingFunctions -> {"Log", "Log", "Log"}, InterpolationOrder -> 0, Contours -> {Log[3]}, ContourShading -> {None, GrayLevel[0.5, 0.36]}, GridLines -> {{0.001, 0.01, 0.1, 1}, {5*10^-4, 10^-3, 2*10^-3, 5*10^-3}}, ContourStyle -> {Thick, Black}] 

With just the InterpolationOrder commented out the contour lines do appear.

 ListContourPlot[data, ScalingFunctions -> {"Log", "Log", "Log"}, (*InterpolationOrder -> 0,*) Contours -> {Log[3]}, ContourShading -> {None, GrayLevel[0.5, 0.36]}, GridLines -> {{0.001, 0.01, 0.1, 1}, {5*10^-4, 10^-3, 2*10^-3, 5*10^-3}}, ContourStyle -> {Thick, Black}] 

What I want is that neither of the regions be shaded but the contour line appear. Which I believed I should get with the code,

ListContourPlot[data, ScalingFunctions -> {"Log", "Log", "Log"}, InterpolationOrder -> 0, Contours -> {Log[3]}, ContourShading -> None, GridLines -> {{0.001, 0.01, 0.1, 1}, {5*10^-4, 10^-3, 2*10^-3, 5*10^-3}}, ContourStyle -> {Thick, Black}] 

But this gives me just nothing. A blank plot.

A sample dataset may be obtained using,

 data = List[{10^-4, 10^-3, Abs[-0.5*Log[10^-4/10^-3]]}]; Do[ Do[ test = Abs[-0.5*Log[i/j]]; data = Join[data, List[{i, j, test}]], {i, 10^-4, 10^-2, 10^-3}], {j, 10^-3, 6, 10^-1}]; 

Update:

@kglr it doesn't work. With the sample data, what I would require is the line between the two regions in

What I get using

if=Interpolation[DeleteDuplicates@data, InterpolationOrder->0]; Quiet@ContourPlot[if[x,y],{x,0,1},{y,0,6},ScalingFunctions->{"Log","Log","Log"}, Contours->{{Log[3]}}, ContourStyle->Directive[Thick, Black],ContourShading->None] 

is

Even the scales don't match up somehow.

$\endgroup$
3
  • 2
    $\begingroup$ Can you please provide a minimal representative data? $\endgroup$ Commented Jul 25, 2018 at 7:29
  • $\begingroup$ Right, dataset to play with would be great. Sound as if something like ArrayMesh[ UnitStep[threshold - data]] could be useful here. $\endgroup$ Commented Jul 25, 2018 at 7:49
  • $\begingroup$ is this close to what you need: if=Interpolation[DeleteDuplicates@data, InterpolationOrder->0]; Quiet@ContourPlot[if[x,y],{x,0,1},{y,0,6},ScalingFunctions->{"Log","Log","Log"}, Contours->{{Log[2]}}, ContourStyle->Directive[Thick, Black],ContourShading->None]? $\endgroup$ Commented Jul 25, 2018 at 13:44

1 Answer 1

2
$\begingroup$

A solution, if not a great solution:

cp = ListContourPlot[data, ScalingFunctions -> {"Log", "Log", "Log"}, Mesh -> Automatic, InterpolationOrder -> 0, Contours -> {Log[3]}, ContourShading -> {Magenta, White}, GridLines -> {{0.001, 0.01, 0.1, 1}, {5*10^-4, 10^-3, 2*10^-3, 5*10^-3}}, ContourStyle -> {Thick, Black}, Method -> {"PolygonReduction" -> True}]; {pos} = Position[cp, Magenta]; contour = ReplacePart[cp, Most@pos -> cp[[1, 2, 1, 1]] /. p : {__Polygon} :> (First@ Show@BoundaryDiscretizeGraphics[ Graphics@GraphicsComplex[cp[[1, 1]], p]] /. _Directive -> Directive[EdgeForm[Directive[Thick, Black]], White] /. Polygon[pts_] :> {Directive[Thick, Black], Line[pts[[1, 52 ;; -1]]]}) ]; Show[cp, contour] 

Shaded contour plot with a thick, black contour line that looks like a staircase

The plot contour contains the desired line. Some manual tweaking of Line[pts[[1, 52 ;; -1]]] was used to find the desired part of the boundary of the polygon.

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.