3
$\begingroup$

I am able to run the following code in earlier versions and get what I want but version 12 gives an error message stating that Coordinates should be a pair of numbers, or a Scaled or Offset form.

Manipulate[
  Plot[0.4 + 0.001 x m, {x, 0, 1400}, 
    PlotRange -> {{0, 1400}, {0, 1.8}}, 
    Epilog -> 
      {Red, 
        {Dashed, Line[{{x, 0}, {x, 0.4 + 0.001 x m}}]}, 
        {Dashed, Line[{{x, 0.4 + 0.001 x m}, {0, 0.4 + 0.001 x m}}]}, 
       Text[
         Style[TraditionalForm[{x, 0.4 + 0.001 x m}], Red, FontSize -> 12], 
         {x + .1, 0.4 + 0.001 x m + .1}]}, 
    ImageSize -> Large], 
  {{m, 1, "Slope"}, 0, 5}, {
  {x, 600, "Change in P & Q"}, 300, 1200}]

I have tried some tricks and codes, but no success.

$\endgroup$
4
  • 1
    $\begingroup$ The problem is that you have x as the independent variable in Plot and as a parameter in Manipulate. That's causing a conflict. Use a different variable inside the Epilog and use that same varaiebl for the Manipulateable variable. $\endgroup$
    – march
    Feb 4, 2020 at 21:55
  • $\begingroup$ Thanks, @march. I did work well. But what I don't understand is that the above code works nicely in earlier versions but not in the new version. $\endgroup$
    – Ilker A
    Feb 4, 2020 at 22:08
  • $\begingroup$ @march That's not exactly the conflict. See my answer. I believe Plot has changed, and what used to be okay no longer is. $\endgroup$
    – Michael E2
    Feb 5, 2020 at 1:26
  • $\begingroup$ To the close-voters: I fail to see how this is a simple mistake, and it is not explained in the documentation. IMHO, it should work as is; alternatively, WRI intentionally changed how Plot works, but did not update the docs. (I can see how wrapping PlotLabel in HoldForm is an improvement, but it was a mistake to extend the rewriting to options like Epilog, imho.) $\endgroup$
    – Michael E2
    Feb 5, 2020 at 19:28

1 Answer 1

7
$\begingroup$

A workaround is to ReleaseHold the plot. Plot has gotten very complicated. I don't really know what they are trying to address exactly. Some of it has to do with data, Quantity[] etc.; some has to do with plot themes; and then there some other stuff I don't get.

Workaround:

Manipulate[
 ReleaseHold@
  Plot[0.4 + 0.001 x m, {x, 0, 1400}, 
   PlotRange -> {{0, 1400}, {0, 1.8}}, 
   Epilog -> {Red, {Dashed, 
      Line[{{x, 0}, {x, 0.4 + 0.001 x m}}]}, {Dashed, 
      Line[{{x, 0.4 + 0.001 x m}, {0, 0.4 + 0.001 x m}}]}, 
     Text[Style[TraditionalForm[{x, 0.4 + 0.001 x m}], Red, 
       FontSize -> 12], {x + .1, 0.4 + 0.001 x m + .1}]}, 
   ImageSize -> Large], {{m, 1, "Slope"}, 0, 
  5}, {{x, 600, "Change in P & Q"}, 300, 1200}]

Note that is it not Manipulate and x being a Manipulate variable that is the problem. It is Plot:

x = 600;
m = 1;
Plot[0.4 + 0.001 x m, {x, 0, 1400},
 PlotRange -> {{0, 1400}, {0, 1.8}}, 
 Epilog -> {Red, {Dashed, 
    Line[{{x, 0}, {x, 0.4 + 0.001 x m}}]}, {Dashed, 
    Line[{{x, 0.4 + 0.001 x m}, {0, 0.4 + 0.001 x m}}]}, 
   Text[Style[TraditionalForm[{x, 0.4 + 0.001 x m}], Red, 
     FontSize -> 12], {x + .1, 0.4 + 0.001 x m + .1}]}, 
 ImageSize -> Large]

Mathematica graphics

If you remove the Epilog, the Plot works fine. If you change the Plot variable in the function and iterator from x to y, it works fine. It is as if someone decided that wherever the iterator variable appears in an option, it should be wrapped by HoldForm[], because no one could possibly want to use the global value of the variable. Maybe someone else can explain this, but it looks like a bug to me.

That said, using the same symbol in the same code for two purposes seems bad or confusing practice.

$\endgroup$
1
  • 2
    $\begingroup$ Instead of ReleaseHold, one can also Evaluate the Epilog: Epilog -> { ..} // Evaluate $\endgroup$
    – Michael E2
    Feb 5, 2020 at 1:27

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.