Is there a way to reliably test the equality of two plots? Consider this:
plot1 = Plot[Sin[x], {x, 0, 2Pi}];
plot2 = Plot[Sin[x], {x, 0, 2Pi}];
You'd think these would be equal, but they're not.
Evaluate[plot1 == plot2]
SameQ
doesn't work either:
Evaluate[plot1 === plot2]
(* False *)
At least this works:
Evaluate[plot1 == plot1]
(* True *)
Edit:
@eyorble provided a nice answer, but the plot thickens. How can we also get False
when two plots are not equal?
plot3 = Plot[Cos[x], {x, 0, 2Pi}];
(plot1 == plot3) /. (x_String :> StringReplace[x, "Charting`Private`Tag$" ~~ __ -> "Charting`Private`Tag"])
Answer
plot1 == plot2 /.
(x_String :> StringReplace[x, "Charting`Private`Tag$" ~~ __ -> "Charting`Private`Tag"])
True
Plots seem to be otherwise deterministic, so that appears to be the only necessary change for comparison with ==
.
To get False
when they aren't equal, perhaps something like this would suffice:
Activate[Inactive[SameQ][plot1, plot2]
/. (x_String :> StringReplace[x, "Charting`Private`Tag$" ~~ __ -> "Charting`Private`Tag"])]
Inactive
and Activate
are simply to ensure that SameQ
doesn't evaluate before the replacement takes place.
Comments
Post a Comment