1
$\begingroup$

I have a notebook which I cannot make to produce the accurate colors. I'll try to post the code hereafter. It looks a bit messy.

Needs["PlotLegends`"]

b1BlSmall = {4.17891*^-1, 5.59816*^-1, 7.09626*^-1, 4.17891*^-1};
b1BlLarge = {3.15389*^-1, 4.73084*^-1, 6.85972*^-1, 3.62698*^-1};
b2BlSmall = {9.74949*^-1, 9.74949*^-1, 9.74949*^-1, 9.74949*^-1};
b2BlLarge = {9.74949*^-1, 9.74949*^-1, 9.74949*^-1, 2.00000};
dbhAdult = {1.00000*^1, 1.00000*^1, 1.00000*^1, 5.48121};

C2B = 2.0
pftColor = {Green, Darker[Green], Darker[Darker[Green]], Magenta};

size2bl[dbh_,ipft_,a_:1,b_:1,c_:1]:=If[ipft!=4,\[Piecewise] b1BlSmall[[ipft]]/C2B*dbh^b2BlSmall[[ipft]] dbh<dbhAdult[[ipft]]
b1BlLarge[[ipft]]/C2B*dbh^b2BlLarge[[ipft]] True 

,\[Piecewise]   (a*b1BlSmall[[ipft]])/C2B*dbh^(b*b2BlSmall[[ipft]]) dbh<dbhAdult[[ipft]]
(a*b1BlLarge[[ipft]])/C2B*dbh^(c*b2BlLarge[[ipft]]) True
];

putzbl[dbh_] := (0.0856*dbh^2 - 0.376)/C2B;


Manipulate[
 Plot[{putzbl[dbh], 
   Evaluate@Table[size2bl[dbh, ipft, a, b, c], {ipft, 1, 4}]}, {dbh, 
   0.0, 11.0},
  PlotStyle -> Flatten[{Black, pftColor}]],
 {a, 0.8, 1.2}, {b, 0.8, 1.2}, {c, 0.8, 1.2}]

But the graph that I get is likeenter image description here

Since I have five curves (the first is a function of its own, the last four are a family of functions of which only one is to manipulate) I was hoping to use a black line for the first curve and the four colors of pftColor for the latter. How do I do that?

EDIT

According to Kuba's answer:

Manipulate[
 Plot[Evaluate@
   Flatten@{putzbl[dbh], 
     Table[size2bl[dbh, ipft, a, b, c], {ipft, 1, 4}]}, {dbh, 0.0, 
   11.0},
  PlotStyle -> Flatten[{Black, pftColor}]],
 {a, 0.8, 1.2}, {b, 0.8, 1.2}, {c, 0.8, 1.2}]

Produce the correct behavior

$\endgroup$
  • $\begingroup$ Your code does not work (at least not in version 11.0.1). Can you make sure that your code works in a new notebook and using a fresh kernel (i.e., after Evaluation -> Quit Kernel)? $\endgroup$ – Felix Jan 17 '17 at 19:20
  • $\begingroup$ You need to come up with a simpler example. The problem here is that you are using PlotStyle ->{color1,{color2, color3, color4}} when you should be using PlotStyle ->{color1, color2, color3, color4}. So replace that option in your code with PlotStyle-> Flatten[{Black,pftColor}] $\endgroup$ – Jason B. Jan 17 '17 at 19:30
  • 1
    $\begingroup$ Evaluate is too deep in Plot to have an effect. But still this nested syntax of PlotStyle is not supported. Flatten those arguments. And inject the table with With. $\endgroup$ – Kuba Jan 17 '17 at 19:31
  • $\begingroup$ Unfortunately I am using Mathematica 7 and I don't think I will be able to upgrade to 11 soon. I tried with flatten but I actually get the same exact figure but with a green color instead of the magenta. $\endgroup$ – Manfredo Jan 17 '17 at 21:18
  • $\begingroup$ @Kuba I tried to look at the With function but it's not clear to me how I should use it in this case. Also if you can think of another, more effective, syntax to produce the plot let me know. $\endgroup$ – Manfredo Jan 18 '17 at 9:11
1
$\begingroup$

dbhAdult is not defined so here is a minimal example of how to fix your problems:

ClearAll[x];
g[x_] := x;
f = {x^2, x^3};
col = {Red, Blue};

Plot[Evaluate @ Flatten @ {g[x], f}, {x, 0, 1}, PlotStyle -> Flatten@{Black, col}]

enter image description here

| improve this answer | |
$\endgroup$

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.