Contour plot in a specific form

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.

Thank you.

• See RegionFunction Jan 29 '18 at 6:14
• How can I use RegionFunction for a piece of a circular form or a triangle? Jan 29 '18 at 6:43
• ContourPlot[ Cos[x] + Cos[y], {x, y} \[Element] Disk[{0, 0}, 4 , {0, \[Pi]/4.}], PlotLegends -> Automatic]
– Kuba
Jan 29 '18 at 11:50

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]


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

• I hope you don't mind the links I inserted, and +1 of course. May 31 '18 at 10:08
• thank you @Mr.Wizard.
– kglr
May 31 '18 at 10:30

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]]


(* 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]
`

• Dear José Antonio Díaz Navas, Thank you. It is what I wanted. Jan 29 '18 at 12:39
• How can I change the angle between the axes from 90 to 45 degrees? Actually, I want to fix the axes on the plot. Jan 29 '18 at 12:52
• @HadiSobhani please elaborate your question. You mean you want the axes to be nonorthogonal? Jan 29 '18 at 13:39
• Exactly. I want the axes to be nonorthogonal. Jan 29 '18 at 14:05