How can one Define a function in the RegionPlot that gives different BoundaryStyle for different sides? I mean


Where Function[something] gives different BoundaryStyles based on the position of x and y.


An alternative approach is to

  1. Post-process RegionPlot output to extract the coordinates of line primitives.
  2. Construct a BSplineFunction for each line using the extracted coordinates.
  3. Use the list of constructed functions to create a list of ParametricPlots each with the desired color function.
  4. Combine the original RegionPlot and constructed ParametricPlots using Show.


rp = RegionPlot[1 <= x^2 + y <= 2 || 3 <= x^2 + y <= 4 || 1 <= x^2 + (y + 2)^2 <= 2, 
  {x, -4, 4}, {y, -4, 4}, PlotPoints -> 60, ImageSize -> Medium];
bsFs = Cases[Normal[rp], Line[x_] :> BSplineFunction[x], All];
colorfuncs = {ColorData["DeepSeaColors"][#2] &, ColorData["SolarColors"][#] &, 
  ColorData["Rainbow"][#3] &, GrayLevel[# + #2] &};
parametricplots = ParametricPlot[ #[t], {t, 0, 1}, PlotStyle -> Thickness[.01], 
   ColorFunction -> #2] & @@@ Transpose[{bsFs, colorfuncs}];
Row[{rp, Show[rp, parametricplots]}, Spacer[5]]

enter image description here


You can do this by post-processing the RegionPlot output. I am assuming that the only line primitives are the region edges and I replace them with lots of single segment lines, individually styled. We need to do Normal to ensure that we have easy access to the line coordinates. For example this will set the edge graylevel to the x coordinate value...

lineStyle[expr_, fn_] := expr /. Line[data_List] :> Map[{fn[#[[1]]], Line[#]} &, Partition[data, 2, 1]]

lineStyle[Normal[RegionPlot[x^2 + y^3 < 2, {x, -2, 2}, {y, -2, 2}]], GrayLevel[#[[1]]/2] &]


Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.