4
$\begingroup$

How can I plot the two functions below with same color for each value of k?

m = 10^-3;
k = {1, 5, 10, 25};
ron = 50 m;
vest[k_, M_] := k ron + ((2 + (-1 + M) M (5 + M)) ron)/(-1 + M)^2;
bb[k_, M_] := M (2 ron + k ron);
Plot[Evaluate[{vest[#, M], bb[#, M]}] & /@ k, {M, 0, 1}]
$\endgroup$
0

4 Answers 4

3
$\begingroup$

With default colors:

Block[{t = Table[{vest[k1, M], bb[k1, M]}, {k1, k}]}, Plot[t, {M, 0, 1}]]

enter image description here

With specified colors and styles:

Block[{t = Table[{vest[k1, M], bb[k1, M]}, {k1, k}]}, 
 Plot[t, {M, 0, 1}, 
  PlotStyle -> {Directive[Blue, Thick], Red, Darker@Green, 
  Directive[Orange, Dashed]}, 
  PlotLegends -> (Row[{HoldForm@k, 
    "\[ThinSpace]=\[ThinSpace]", #}] & /@ k)]]

enter image description here

$\endgroup$
5
$\begingroup$

Evaluate the complete plot-argument:

Show[Map[Plot[ {vest[#, M], bb[#, M]},{M,0, 1},Evaluated -> True, 
PlotStyle -> RGBColor[#/Max[k],0,1-#/Max[k]]] &, k], PlotRange -> All]

enter image description here

$\endgroup$
4
  • $\begingroup$ this's not what I said. I want both function vest and bb have the same color for each k like vest and bb have same red for k = 1 and same blue for k = 2 and so on $\endgroup$
    – emnha
    Nov 27, 2019 at 17:44
  • $\begingroup$ Ok, see my modiefied answer. $\endgroup$ Nov 27, 2019 at 17:55
  • $\begingroup$ My color above is just an example. That color is hard to distinguish, how can I change the colors? $\endgroup$
    – emnha
    Nov 27, 2019 at 18:04
  • 1
    $\begingroup$ Perhaps you find some information in the documentation of PlotStyle . Try PlotStyle -> Blend[{Red, Green, Blue}, #/Max[k]] $\endgroup$ Nov 27, 2019 at 18:32
3
$\begingroup$
m = 10^-3;
k = {1, 5, 10, 25};
ron = 50m;
dcr = k ron;
vest[k_, M_] := k ron + (2 + (-1 + M) M (5 + M)) ron/(-1+M)^2;
bb[k_, M_]:= (2 ron+k ron);
Plot[
 Evaluate @ Flatten @ {Map[{vest[#,M],bb[#,M]}&]@k}]
 ,{M,0,1}
 ,PlotStyle-> {Green,Green,Red,Red,Blue,Blue,Orange,Orange}
]

enter image description here

$\endgroup$
1
  • $\begingroup$ that looks nice but I don't think the curves with the same k don't have the same color. Also you changed the bb function! $\endgroup$
    – emnha
    Nov 27, 2019 at 20:47
3
$\begingroup$

Another possibility is to use Style wrappers around the individual functions. This enables you to have both data and appearance specified in the same place:

m = 10^-3;
k = {1, 5, 10, 25};
ron = 50 m;
vest[k_, M_] := k ron + ((2 + (-1 + M) M (5 + M)) ron)/(-1 + M)^2;
bb[k_, M_] := M (2 ron + k ron);
Plot[
 Evaluate[
  Style[
     {vest[#, M], bb[#, M]}, 
     ColorData["Rainbow"][#/Max@k]
    ] & /@ k
  ],
 {M, 0, 1}
 ]

enter image description here

Note the use of Evaluate, similar to the other answers.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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