4
$\begingroup$

I have implemented a simple climate model for my students to play around with in Mathematica. There is a multi-panel plot; the first has CO2 emissions, and you can drag the line around to set up whatever emissions scenario you care to. The second shows the resulting atmospheric CO2 abundance. Finally, there's a panel that shows the temperature trajectory.

This worked fine in Mathematica 10, but (I think) 11 broke it. Now I can't drag the emissions line around — it seems to think the symbols are in another panel.

Here's some code so you can reproduce the problem. First, here is a 2-panel example that works well:

Manipulate[
 lx1 = Sort[lx1, #1[[1]] < #2[[1]] &]; 
 If[lx1[[1]][[1]] < 2015, lx1[[1]][[1]] = 2015];
 f = Interpolation[Join[{{2000, 7}, {2010, 11}}, lx1, {{2500, 0}}]];
 co2x = NDSolve[{c'[t] == f[t]/3. - c[t]/300., c[2010] == 390.}, 
   c, {t, 2000, 2100}];
 tempx = NDSolve[{35 T'[t] == -30.07 + 5.337 Log[c[t]] - 1.749 + 
       0.5 - 3.7/sens T[t] /. co2x, T[2000] == 0.}, 
   T, {t, 2000, 2100}];
 Grid[
  {
   {
    Show[Plot[fi[x], {x, 2000, 2100}, PlotStyle -> Red, 
       ImageSize -> Scaled[0.45], PlotRange -> {0, 30}, 
      GridLines -> Automatic], ListPlot[lx1, Joined -> True], 
 Frame -> True, FrameLabel -> {"year", "CO2 emissions (GtC/yr)"}, 
 LabelStyle -> Directive[Medium]],
Plot[c[x] /. co2x, {x, 2000, 2100}, ImageSize -> Scaled[0.45], 
 PlotRange -> {250, 900}, GridLines -> Automatic, Frame -> True, 
 FrameLabel -> {"year", "CO2 abundance (ppm)"}, 
 LabelStyle -> Directive[Medium]]
},
   {}
   }], {{lx1, Table[{i, fi[i]}, {i, 2020, 2100, 10}]}, 
  Locator}, {{sens, 3, "sensitivity"}, 1.5, 
  4.5}, {{targ, 2, "climate target"}, 1, 3}, 
 Initialization :> (lx = {{2000, 7}, {2010, 11}, {2020, 14}, {2030, 
      16}, {2040, 20}, {2050, 24}, {2060, 25}, {2070, 26}, {2080, 
      27}, {2090, 26}, {2100, 25}}; 
   fi[t1_] := Fit[lx, {1, t, t^2}, t] /. t -> t1), 
 ContinuousAction -> False]

Here's what it looks like: enter image description here

When I add a panel showing the resulting temperature, things break:

Manipulate[
 lx1 = Sort[lx1, #1[[1]] < #2[[1]] &]; 
 If[lx1[[1]][[1]] < 2015, lx1[[1]][[1]] = 2015];
 f = Interpolation[Join[{{2000, 7}, {2010, 11}}, lx1, {{2500, 0}}]];
 co2x = NDSolve[{c'[t] == f[t]/3. - c[t]/300., c[2010] == 390.}, 
   c, {t, 2000, 2100}];
 tempx = NDSolve[{35 T'[t] == -30.07 + 5.337 Log[c[t]] - 1.749 + 
       0.5 - 3.7/sens T[t] /. co2x, T[2000] == 0.}, 
   T, {t, 2000, 2100}];
 Grid[
  {
   {
    Show[Plot[fi[x], {x, 2000, 2100}, PlotStyle -> Red, 
      ImageSize -> Scaled[0.45], PlotRange -> {0, 30}, 
      GridLines -> Automatic], ListPlot[lx1, Joined -> True], 
     Frame -> True, FrameLabel -> {"year", "CO2 emissions (GtC/yr)"}, 
     LabelStyle -> Directive[Medium]],
   Plot[c[x] /. co2x, {x, 2000, 2100}, ImageSize -> Scaled[0.45], 
     PlotRange -> {250, 900}, GridLines -> Automatic, Frame -> True, 
 FrameLabel -> {"year", "CO2 abundance (ppm)"}, 
 LabelStyle -> Directive[Medium]]
},
   {Show[Plot[T[x] + 0.8 /. tempx, {x, 2000, 2100}, 
  ImageSize -> Scaled[0.45], PlotRange -> {0, 5}, 
  GridLines -> Automatic], 
 Graphics[{Red, Line[{{2000, targ}, {2100, targ}}]}], 
 Frame -> True, 
 FrameLabel -> {"year", "Temperature anomaly (\[Degree]C)"}, 
 LabelStyle -> Directive[Medium]], Graphics[{
  Text[
   Style[Column[{Row[{"Sensitivity = " , NumberForm[sens, {4, 1}],
         "\[Degree]C"}],

      Row[{"T in 2100 = " , 
        NumberForm[T[2100] + 0.8 /. tempx[[1]], {4, 1}], 
        "\[Degree]C"}],

      Row[{"Total emissions = " , 
        NumberForm[500 + NIntegrate[f[x], {x, 2014, 2100}], {4}], 
        "GtC"}]}], FontSize -> 14], Scaled[{0.2, 1.2}]]
  }]}
  }], {{lx1, Table[{i, fi[i]}, {i, 2020, 2100, 10}]}, 
  Locator}, {{sens, 3, "sensitivity"}, 1.5, 
  4.5}, {{targ, 2, "climate target"}, 1, 3}, 
 Initialization :> (lx = {{2000, 7}, {2010, 11}, {2020, 14}, {2030, 
      16}, {2040, 20}, {2050, 24}, {2060, 25}, {2070, 26}, {2080, 
      27}, {2090, 26}, {2100, 25}}; 
   fi[t1_] := Fit[lx, {1, t, t^2}, t] /. t -> t1), 
 ContinuousAction -> False]

Note that the code doesn't put the locator symbols on the line, and when I try to drag the line the symbols appear on the bottom panel. And the line doesn't move right.

Here's what it looks like: enter image description here

Any suggestions for what I'm doing wrong here?

$\endgroup$
2

1 Answer 1

2
$\begingroup$

Using LocatorPane[Dynamic@lx1, ...] and setting the ControlType->None for lx1 seems to work. This answer is derived from the comments in Assign Locator points to a specific plot


Manipulate[lx1 = Sort[lx1, #1[[1]] < #2[[1]] &];
 If[lx1[[1]][[1]] < 2015, lx1[[1]][[1]] = 2015];
 f = Interpolation[Join[{{2000, 7}, {2010, 11}}, lx1, {{2500, 0}}]];
 co2x = NDSolve[{c'[t] == f[t]/3. - c[t]/300., c[2010] == 390.}, 
   c, {t, 2000, 2100}];
 tempx = NDSolve[{35 T'[t] == -30.07 + 5.337 Log[c[t]] - 1.749 + 
       0.5 - 3.7/sens T[t] /. co2x, T[2000] == 0.}, 
   T, {t, 2000, 2100}];
 p1 = Plot[fi[x], {x, 2000, 2100}, PlotStyle -> Red, 
   ImageSize -> Scaled[0.45], PlotRange -> {0, 30}, 
   GridLines -> Automatic];
 p2 = ListPlot[lx1, Joined -> True, 
   Epilog -> {Dynamic@Locator@Dynamic@lx1}];
 p12 = Show[p1, p2, Frame -> True, 
   FrameLabel -> {"year", "CO2 emissions (GtC/yr)"}, 
   LabelStyle -> Directive[Medium]];
 p3 = Plot[c[x] /. co2x, {x, 2000, 2100}, ImageSize -> Scaled[0.45], 
   PlotRange -> {250, 900}, GridLines -> Automatic, Frame -> True, 
   FrameLabel -> {"year", "CO2 abundance (ppm)"}, 
   LabelStyle -> Directive[Medium]];
 Grid[{{LocatorPane[Dynamic@lx1, p12, ContinuousAction -> False], 
    p3}, {Show[
     Plot[T[x] + 0.8 /. tempx, {x, 2000, 2100}, 
      ImageSize -> Scaled[0.45], PlotRange -> {0, 5}, 
      GridLines -> Automatic], 
     Graphics[{Red, Line[{{2000, targ}, {2100, targ}}]}], 
     Frame -> True, 
     FrameLabel -> {"year", "Temperature anomaly (\[Degree]C)"}, 
     LabelStyle -> Directive[Medium]], 
    Graphics[{Text[
       Style[Column[{Row[{"Sensitivity = ", NumberForm[sens, {4, 1}], 
            "\[Degree]C"}], 
          Row[{"T in 2100 = ", 
            NumberForm[T[2100] + 0.8 /. tempx[[1]], {4, 1}], 
            "\[Degree]C"}], 
          Row[{"Total emissions = ", 
            NumberForm[500 + NIntegrate[f[x], {x, 2014, 2100}], {4}], 
            "GtC"}]}], FontSize -> 14]
       , Scaled[{0.2, 1.2}]]}]}}]
 , {{lx1, Table[{i, fi[i]}, {i, 2020, 2100, 10}]}, ControlType -> None}
 , {{sens, 3, "sensitivity"}, 1.5, 4.5}
 , {{targ, 2, "climate target"}, 1, 3}, 
 Initialization :> (lx = {{2000, 7}, {2010, 11}, {2020, 14}, {2030, 
      16}, {2040, 20}, {2050, 24}, {2060, 25}, {2070, 26}, {2080, 
      27}, {2090, 26}, {2100, 25}};
   fi[t1_] := Fit[lx, {1, t, t^2}, t] /. t -> t1), 
 ContinuousAction -> False]

$\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.