Message Boards Message Boards

0
|
4006 Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How to draw several contours label in separate colors?

Good morning. I have two equations (or more) that I want plot with ContourPlot colored with different colours and labelled according to equation order, in a automatic way. I have tried several solutions without success. My plot should remain as

g1 = x + 2 y; g2 = 2 x + y; b = {2, 2};

coloresRest = {Blue, Magenta}; labelRest = 
 Table[Text[Style["(" <> ToString@i <> ")", coloresRest[[i]]]], {i, 
   Length@coloresRest}];

ContourPlot[{g1 == b[[1]], g2 == b[[2]]}, {x, -2, 
  4}, {y, -2, 4}, Frame -> False, Axes -> True, 
 ContourStyle -> Thread[{coloresRest, grosor}], 
 Epilog -> {Text[Style["(1)", color3], Offset[{20, 0}, {-2, 2}]], 
   Text[Style["(2)", color4], Offset[{-10, -10}, {-1, 4}]]}, 
 ImageSize -> 400]

enter image description here

I have tried with Table, ContourLabel, Riffle or Epilog, without success. For example:

ContourPlot[{g1 == b[[1]], g2 == b[[2]]}, {x, -2, 
  4}, {y, -2, 4}, Frame -> False, Axes -> True, 
 ContourStyle -> Thread[{coloresRest, grosor}], 
 ContourLabels -> 
  Table[Text[Style[labelRest[[i]], Offset[{10, 0}, {#1, #2} &]]], {i, 
    1, Length@coloresRest}], ImageSize -> 400]

or

ContourPlot[{g1 == b[[1]], g2 == b[[2]]}, {x, -2, 
  4}, {y, -2, 4}, Frame -> False, Axes -> True, 
 ContourStyle -> Thread[{coloresRest, grosor}], 
 ContourLabels -> {Riffle[coloresRest, 
    Inset[labelRest, Offset[{10, 0}, {#1, #2} &]]]}, ImageSize -> 400]

I realize that expression {#1, #2}& yield coordinates for labels, chosen by Mathematica. I'd prefer that and not to choose such coordinates.

Thank in advance

POSTED BY: Rafael Rodriguez
4 Replies
Posted 2 years ago

Crossposted here.

POSTED BY: Rohit Namjoshi

It's easiest to make 2 different contour plots, each with its own contour style, and combine them using show.

POSTED BY: Yaroslav Bulatov

Sorry,

grosor = Thickness[0.01], color3=Blue, color4=Magenta

Thank

POSTED BY: Rafael Rodriguez
Posted 2 years ago

What are the definitions of grosor, color3, color4?

POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract