2

I want to plot a contour plot in Mathematica. In normal and common case the plot will be shown in a square form but I want to have a plot in a triangle and a piece of circle form (disk-segment). How can I figure it out?

Suppose I have the following contour plot:

ClearAll["Global`*"]
ContourPlot[Cos[x] + Cos[y], {x, 0, 4 Pi}, {y, 0, 4 Pi},  PlotLegends -> Automatic]

and I want to have the plot like the following figure.enter image description here

Thank you.

AYBRXQD
  • 1,085
  • 6
  • 16

2 Answers2

4

You can use ContourPlot for Textureing a ParametricPlot showing the desired polar region to get something close to the desired picture:

cp1 = ContourPlot[Cos[x] Cos[y], {x, -Pi/2, Pi/2}, {y, -Pi/2, Pi/2}, 
   PlotRangePadding -> 0, Frame -> False, ColorFunction -> "Rainbow", 
   PerformanceGoal -> "Quality", PlotPoints -> 100, 
   MaxRecursion -> 5, ContourStyle -> Thick, ImageSize -> 300];
cp2 = ContourPlot[Cos[x] + Cos[y], {x, -Pi, Pi}, {y, -Pi, Pi}, 
   PlotRangePadding -> 0, Frame -> False, ColorFunction -> "Rainbow", 
   PerformanceGoal -> "Quality", PlotPoints -> 100, 
   MaxRecursion -> 5, ContourStyle -> Thick, ImageSize -> 300];
{pp1, pp2} = ParametricPlot[{v Cos[u], v Sin[u]}, {u, 0, Pi/4}, {v, .1, 1}, 
   PlotStyle -> Texture[#], Mesh -> None, PlotRange -> {0, 1}, 
   ImageSize -> 300, Frame -> False, Axes -> False] /. Opacity[_] :> Opacity[1] & /@ 
  {cp1, cp2};

Grid[{{"", Style[ContourPlot,20, "Panel", Bold], Style[ParametricPlot,20, "Panel", Bold]},
 {Rotate[Style[TraditionalForm[Cos[x] Cos[y]], 20, "Panel", Bold], Pi/2], cp1, pp1},
 {Rotate[Style[TraditionalForm[Cos[x] +  Cos[y]], 20, "Panel", Bold], Pi/2], cp2, pp2}}, 
  Dividers -> All] 

enter image description here

Use {u, -Pi, Pi}, and {v, 0, 1} in ParametricPlot above to get

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896
3

by using RegionFunction:

(* in a sector *)
ContourPlot[Cos[x] + Cos[y], {x, 0, 4}, {y, 0, 4}, 
PlotLegends -> Automatic,
RegionFunction -> Function[{x, y}, 
                  0.5 <= Sqrt[x^2 + y^2] <= 4 && 0. <= ArcTan[x, y] <= \[Pi]/4]]

enter image description here

(* in a triangle *)
ContourPlot[Cos[x] + Cos[y], {x, 0, 4}, {y, 0, 4}, 
PlotLegends -> Automatic,
RegionFunction -> Function[{x, y}, y <= x + 1 && y <= -3/4 x + 4 && y >= 1]

enter image description here