Testing equality of graphics

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.


As I observed earlier, the tags are used in plots in the form Annotation[curve, tag] for each function plotted. One way to just get the curves is to override Annotation:

Block[{Annotation = #1 &},
 plot1 == plot2
 ]
(*  True  *)

Block[{Annotation = #1 &},
 plot1 === plot2
 ]
(*  True  *)

Since the tags are in the Charting`Private` context, it seems pointless to have them in the first place. (Even if they are used in constructing the plot, what good are they in the final output, ostensibly private and hidden from the user?)

Note on Equal vs. SameQ: Equal will evaluate to True when expressions are the same (as in SameQ), but it tends to remain unevaluated if there are symbols (which might take on arbitrary values). To be sure to get a False, use SameQ:

Plus == Automatic
(*  Plus == Automatic  *)

Plus === Automatic
(*  False  *)

See 1 is not the SameQ as Null, but why might 1 be Equal to Null?

Also related: (4390), (8796), (17909).


If by equal you mean the plots look the same and are the same size then you can use Rasterize and ImageData.

samePlot[p1_, p2_] := Equal @@ (ImageData@Rasterize[#, "Image"] & /@ {p1, p2})

With

plot1 = Plot[Sin[x], {x, 0, 2 Pi}];
plot2 = Plot[Sin[x], {x, 0, 2 Pi}];
plot3 = Plot[Cos[x], {x, 0, 2 Pi}];

Then

samePlot[plot1, plot2]
True
samePlot[plot1, plot3]
False

Hope this helps.