# Problem get the difference between two plots using their data

Everyone :)

In the next algoritm I made two set data (NFW1tbcx.dat and SIS1tbcx.dat) with which I make two different plots and I need to make a third plot that would be the difference of the previous two, so the easy path is take both set data and obtain the diference between them making a new data file which will be plotted. Lets start with the algoritm.

First we define some functions

NFWint[x_]=Assuming[x > 0 && x < 1,   0.5 ((Log[x/2])^2 -
(ArcTanh[Sqrt[1 - x^2]])^2)]

NFWext[x_] = Assuming[x > 1, 0.5 ((Log[x/2])^2 + (ArcTan[Sqrt[x^2 - 1]])^2)]

NFWp[x_] =  Piecewise[{{NFWint[x], x > 0 && x < 1}, {NFWext[x], x > 1}}]

SISp[x_] = Piecewise[{{x, 0 < x < 1}, {x, x > 1}}]


Now we define some integrals that use the already defined functions

FNFWint[y_?NumericQ, w_?NumericQ, g_?NumericQ, cro_?NumericQ] := -I*10^w*
Exp[0.5*I*10^w*y^2]*NIntegrate[x*(BesselJ[0, 10^w*x*y])*
Exp[I*10^w*(0.5*x^2 - NFWp[x] + cro)], {x,0.001, g}, WorkingPrecision -> 16,
MaxRecursion -> 30,
Method -> {GlobalAdaptive, MaxErrorIncreases -> 10000}]

FNFWext[y_?NumericQ, w_?NumericQ, g_?NumericQ, cro_?NumericQ] :=
-I*10^w*Exp[0.5*I*10^w*y^2]*NIntegrate[x*(BesselJ[0, 10^w*x*y])
*Exp[I*10^w*(0.5*x^2 - NFWp[x] + cro)], {x,
1.001, g}, WorkingPrecision -> 16, MaxRecursion -> 30,

FSISint[y_?NumericQ, w_?NumericQ, g_?NumericQ] :=
-I*10^w*Exp[0.5*I*10^w*y^2]*NIntegrate[x*(BesselJ[0, 10^w*x*y])*
Exp[I*10^w*(0.5*x^2 - SISp[x] + y + 0.5)], {x, 0.001, g}]

FSISext[y_?NumericQ, w_?NumericQ, g_?NumericQ] := -I*10^w*
Exp[0.5*I*10^w*y^2]*
NIntegrate[x*(BesselJ[0, 10^w*x*y])*
Exp[I*10^w*(0.5*x^2 - SISp[x] + y + 0.5)], {x, 1.001, g},
WorkingPrecision -> 16, MaxRecursion -> 30]


and now we start create and manipulate some data until we obtain the first set data NFW1tbcx.dat

NFWtbcxa1 =  Table[{10^w, FNFWint[0.1, w, 0.9999, 0.0243401]}, {w, -3, 2, 0.001}]

NFWtbcxa2 =  Table[{10^w, FNFWext[0.1, w, 200000, 0.0243401]}, {w, -3, 2, 0.001}]

NFWtbcxa1[[All, 1]] = 0; NFWtbcxa1

NFW1tbcx = {NFWtbcxa1} + {NFWtbcxa2}

NFW1tbcx[[1, All, 2]] = Norm /@ NFW1tbcx[[1, All, 2]]; NFW1tbcx

Export["NFW1tbcx.dat",NFW1tbcx]


this is the plot with the data NFW1tbcx

NFW1 = ListLogLogPlot[NFW1tbcx, Frame -> True,
PlotRange -> {{0.001, 100}, {.25, 10}}, AspectRatio -> 1,
ImageSize -> Large, FrameTicks -> All, GridLines -> Automatic,
PlotStyle -> Black, PlotMarkers -> {Automatic, 2}]


Now we create a 2nd groups of data to obtain the remaining SIS1tbcx.dat

SIStbcxinta1 = Table[{10^w, FSISint[0.1, w, 0.9999]}, {w, -3, 2, 0.001}]

SIStbcxexta1 = Table[{10^w, FSISext[0.1, w, 200000]}, {w, -3, 2, 0.001}]

SIStbcxinta1[[All, 1]] = 0; SIStbcxinta1

SIS1tbcx = {SIStbcxinta1} + {SIStbcxexta1}

SIS1tbcx[[1, All, 2]] = Norm /@ SIS1tbcx[[1, All, 2]]; SIS1tbcx

Export["SIS1tbcx.dat",SIS1tbcx]


this is the plot with the data SIS1tbcx

SIS1 = ListLogLogPlot[SIS1tbcx, Frame -> True,
PlotRange -> {{0.001, 100}, {.25, 10}}, AspectRatio -> 1,
ImageSize -> Large, FrameTicks -> All, GridLines -> Automatic,
PlotStyle -> Red, PlotMarkers -> {Automatic, 2}]


Both plots are

As you can see both are totally diferent shape, but I need a new plot defined like, lets say plot Red - Plot Black

My first try to do this "diference between those two plots" is using the command Transpose like this thread suggest using NFW1tbcx.dat and SIS1tbcx.dat to get a new file dat called DIFNFWSIS1, and the plot that new file, like this

DIFNFW1SIS1 = Transpose[{NFW1tbcx[[All, 1]], (NFW1tbcx - SIS1tbcx)[[All, 2]]}]


and...epic fail

{{{0.001, 0.912362}, {0., 0.0760613}}}


my 2nd attemp is another suggestion in the same thread, just like this

DIFNFW1SIS12 = NFW1tbcx[[All, 2]] - SIS1tbcx[[All, 2]]


and...epic fail again :\

{{0., 0.0760613}}


someone can give a hint to get the difference betwen those two plots.

• Wait, why do you do NFW1tbcx = {NFWtbcxa1} + {NFWtbcxa2} and not NFW1tbcx = Join[NFWtbcxa1, NFWtbcxa2]? If you used Join then something like DIFNFW1SIS1 = Transpose[{NFW1tbcx[[All, 1]], NFW1tbcx[[All, 2]] - SIS1tbcx[[All,2]]}] would probably do the trick. – Marius Ladegård Meyer Sep 1 '18 at 7:14