2
$\begingroup$

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.

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

2 Answers 2

4
$\begingroup$

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

$\endgroup$
2
  • $\begingroup$ I hope you don't mind the links I inserted, and +1 of course. $\endgroup$ Commented May 31, 2018 at 10:08
  • $\begingroup$ thank you @Mr.Wizard. $\endgroup$ Commented May 31, 2018 at 10:30
3
$\begingroup$

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

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.