3
$\begingroup$

Consider example

 ContourPlot[{(x - 2)^2 + (y - 2)^2 == 12, (x + 2)^3 + (y + 2)^3 ==8}, {x, -4, 4}, {y, -4, 4}, PlotLegends -> Placed[{Style["Region 1", 20], Style["Region 2", 20]}, {0.7, 0.82}]] 

The result is the picture on the left. Could you please tell me to change the colour of the legend text and set for each plot legend set its own coordinate, see the picture on the right?

enter image description here

$\endgroup$

2 Answers 2

7
$\begingroup$

Try this:

Show[{ ContourPlot[{(x - 2)^2 + (y - 2)^2 == 12, (x + 2)^3 + (y + 2)^3 == 8}, {x, -4, 4}, {y, -4, 4}, ContourStyle -> {Blue, Orange}], Graphics[{Text[Style["Region 1", 20, Blue], Scaled[{0.8, 0.8}]], Text[Style["Region 2", 20, Orange], Scaled[{0.2, 0.2}]] }] }] 

enter image description here

Done. Have fun!

$\endgroup$
1
  • $\begingroup$ Maybe a bit more "authomatic": Show[ContourPlot[(x - 2)^2 + (y - 2)^2 == 12, {x, -4, 4}, {y, -4, 4}, ContourStyle -> Blue, PlotLegends -> Placed[{"Region 1"}, {Right, Top}]], ContourPlot[(x + 2)^3 + (y + 2)^3 == 8, {x, -4, 4}, {y, -4, 4}, ContourStyle -> Orange, PlotLegends -> Placed[{"Region 2"}, {Left, Bottom}]]] $\endgroup$ Commented Nov 1, 2018 at 10:04
5
$\begingroup$
labels = Style[#, 20] & /@ {"Region 1", "Region 2"}; colors = ColorData[97] /@ {1, 2}; positions = {{7, 7} / 10, {1, 1} / 4}; ContourPlot[{(x - 2)^2 + (y - 2)^2 == 12, (x + 2)^3 + (y + 2)^3 == 8}, {x, -4, 4}, {y, -4, 4}, PlotLegends -> ( Placed[Style@##2, #] & @@@ Transpose[{positions, labels, colors}])] 

enter image description here

Alternatively, you can replace PlotLegends -> ... with

Epilog -> (Text[Style[##2], Scaled@#] & @@@ Transpose[{positions, labels, colors}]) 

to get the same picture.

Update: You can also get positions using ImplicitRegion and RegionCentroid :

contours = {(x - 2)^2 + (y - 2)^2 == 12, (x + 2)^3 + (y + 2)^3 == 8} ; positions = Quiet @ N @ RegionCentroid[ImplicitRegion[# /. Equal -> LessEqual, {{x, -4, 4}, {y, -4, 4} }] ] & /@ contours 

{{1.46315, 1.46315}, {-2.03791, -2.03791}}

Notes: (1) Despite the warning message (suppressed above with Quiet) RegionCentroid gives the correct coordinates. (2) If you use this with Epilog you should remove Scaled.

$\endgroup$
1
  • 1
    $\begingroup$ Nice answer, first time I've ever seen ##n used. $\endgroup$ Commented Nov 1, 2018 at 15:16

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.