12
$\begingroup$

In version 10.1 I found a strange Plot behavior I did not anticipate. It seems that various heads including PlusMinus are treated as wrappers and stripped by Plot in a way that is not safe. This means that definitions that do not appear in the plot expression can radically and errantly affect its output:

ClearAll[PlusMinus]
Plot[x^2, {x, -1, 1}]

enter image description here

PlusMinus = Power;
Plot[x^2, {x, -1, 1}]

enter image description here

Surely this is a bug? What versions are affected? What is the easiest way to patch this in version 10.1?

$\endgroup$
  • 1
    $\begingroup$ v9.0.1 is not affected: i.stack.imgur.com/IpBYU.png. Persisting through v12.1. (Tested on Wolfram cloud. ) $\endgroup$ – xzczd May 22 at 10:50
  • 1
    $\begingroup$ I think this may be the function that needs leak-proofing: Charting`ParserDump`plotStripWrappers $\endgroup$ – Mr.Wizard May 22 at 10:58
  • $\begingroup$ Bug also present in v11.2. $\endgroup$ – Rebel-Scum May 22 at 11:06
  • $\begingroup$ Further check shows Charting`ParserDump` context doesn't seem to exist in v9.0.1. $\endgroup$ – xzczd May 22 at 11:09
12
$\begingroup$

It appears that PlusMinus is the only wrapper that is not Protected:

Charting`PlotParser; (* preload *)

Select[Charting`ParserDump`$pAllWrappers, FreeQ[Protected]@*Attributes]
{PlusMinus}

We can remove it from that list to correct this bug, but perhaps induce others:

Charting`PlotParser; (* preload; do not remove! *)

With[{ov := OwnValues @ Charting`ParserDump`$pAllWrappers},
  ov = DeleteCases[ov, HoldPattern[PlusMinus], {3}];
]
| 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.