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

| improve this answer | |
$\endgroup$
  • $\begingroup$ I hope you don't mind the links I inserted, and +1 of course. $\endgroup$ – Mr.Wizard May 31 '18 at 10:08
  • $\begingroup$ thank you @Mr.Wizard. $\endgroup$ – kglr May 31 '18 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

| improve this answer | |
$\endgroup$
  • $\begingroup$ Dear José Antonio Díaz Navas, Thank you. It is what I wanted. $\endgroup$ – AYBRXQD Jan 29 '18 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$ – AYBRXQD Jan 29 '18 at 12:52
  • $\begingroup$ @HadiSobhani please elaborate your question. You mean you want the axes to be nonorthogonal? $\endgroup$ – José Antonio Díaz Navas Jan 29 '18 at 13:39
  • $\begingroup$ Exactly. I want the axes to be nonorthogonal. $\endgroup$ – AYBRXQD Jan 29 '18 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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