0
$\begingroup$

I have an analytical 1d-function of a variable called $M$ and I have plotted that function using the following code:

yfunc[M_] := 10^(12 - M);
sigma[M_] := (16.9*(yfunc[M])^0.41)/(1 + 1.102*(yfunc[M])^0.20 + 6.22*(yfunc[M])^0.333);
dsigmadM[M_] := (Log[10]*10^M)^-1*D[sigma[x], x] //. x -> M;
xfunc[M_] := 1.686/sigma[M];
func[M_] := 0.322*Sqrt[(2*0.707)/\[Pi]]*(1 + (0.707*(xfunc[M])^2)^-0.3)* xfunc[M]*Exp[-((0.707*(xfunc[M])^2)/2)];
h[M_] := -0.05152*10^12*func[M]/sigma[M]*dsigmadM[M];
f[M_] := 0.54*(M - 12) + 2.73;
g[M_?NumericQ] := 1301.98*(0.7)^2*10^-6*NIntegrate[(10^f[x])*h[x]*Log[10], {x, M, \[Infinity]}];


LogPlot[g[M], {M, 8, 16}, PlotRange -> {10^-17, 10}, 
             Frame -> True, 
             FrameLabel -> {Style["Log(M)", FontSize -> 24], Style["Y-axis Log scale", FontSize -> 24]}, 
             FrameTicksStyle -> Directive[FontSize -> 24]]

I also have a set of 32 discrete points $(M, u[M])$ corresponding to some other function whose analytical form is unknown but it is fair enough to join the data points in a dot-to-dot manner. I was able to do so using the following code:

    a = 25;
    MyData = {{8.90 + Log10[a], 0.0003256}, {9.0 + Log10[a], 
        0.0002971}, {9.10 + Log10[a], 0.0002980}, {9.20 + Log10[a], 
        0.0002757}, {9.30 + Log10[a], 0.0002546}, {9.40 + Log10[a], 
        0.0002400}, {9.50 + Log10[a], 0.0002253}, {9.60 + Log10[a], 
        0.0002015}, {9.70 + Log10[a], 0.0001900}, {9.80 + Log10[a], 
        0.0001856}, {9.90 + Log10[a], 0.0001750}, {10.0 + Log10[a], 
        0.0001753}, {10.10 + Log10[a], 0.0001732}, {10.20 + Log10[a], 
        0.0001692}, {10.30 + Log10[a], 0.0001630}, {10.40 + Log10[a], 
        0.0001503}, {10.50 + Log10[a], 0.0001309}, {10.60 + Log10[a], 
        0.0001135}, {10.70 + Log10[a], 0.00009117}, {10.80 + Log10[a], 
        0.00007193}, {10.90 + Log10[a], 0.00005419}, {11.00 + Log10[a], 
        0.00003707}, {11.10 + Log10[a], 0.00002439}, {11.20 + Log10[a], 
        0.00001501}, {11.30 + Log10[a], 0.000008719}, {11.40 + Log10[a], 
        0.000004783}, {11.50 + Log10[a], 0.000002529}, {11.60 + Log10[a], 
        0.000001170}, {11.70 + Log10[a], 0.0000004598}, {11.80 + Log10[a],
         0.0000001803}, {11.90 + Log10[a], 
        0.00000006044}, {12.00 + Log10[a], 0.00000001651}};
    error = {0.0000146, 0.0000119, 0.0000112, 0.00000903, 0.00000774, 
       0.00000672, 0.00000578, 0.00000469, 0.00000443, 0.00000389, 
       0.00000325, 0.00000326, 0.00000281, 0.00000235, 0.00000227, 
       0.00000174, 0.00000152, 0.00000131, 0.00000106, 0.000000833, 
       0.000000627, 0.000000429, 0.000000339, 0.000000244, 0.000000162, 
       0.000000100, 0.0000000709, 0.0000000411, 0.0000000239, 
       0.0000000142, 0.00000000769, 0.00000000390};
    withError = Transpose[{MyData[[All, 1]], MyData[[All, 2]], error}];
    errorplot = ErrorListPlot[withError, Joined -> True, Frame -> True];
    lerrorplot = errorplot /. {x_Real, y_Real} -> {x, Log@y};
    Show[ListLogPlot[MyData, PlotRange -> {10^-17, 10}, 
    PlotStyle -> {Red, Thick}, Joined -> True, Frame -> True, 
    FrameLabel -> {Style["Log(M)", FontSize -> 24], Style["Y-axis Log scale", FontSize -> 24]}, 
    FrameTicksStyle -> Directive[FontSize -> 24]], lerrorplot]

Now, I am trying to merge two plots into one by adding my second set of data points into my first plot. My first question is how to do it? and my second question is assuming $a$ is the Interval[50 + 25 {-1, 1}] rather than a fixed value of $a=25,$ how to plot the confidence region of the best fit (or joined data) on the single plot produced by merging the two?

Your help is appreciated,

$\endgroup$
  • 1
    $\begingroup$ can Show function do the job? $\endgroup$ – Wjx Jun 9 '16 at 7:12
  • $\begingroup$ Minimalistic examples are nice. I would strip away all of the formatting code, such that your goal would be more clear. $\endgroup$ – Johu Jun 9 '16 at 7:13
  • $\begingroup$ We can not even test your code, as we don't have {f[M], g[M], h[M], p[M], q[M]} definitions. Instead of ugly old PlotLegends`, check out option for most Plots called PlotLegends. $\endgroup$ – Johu Jun 9 '16 at 7:16
  • $\begingroup$ @Wjx, I tried Show. It didn't work. $\endgroup$ – Benjamin Jun 9 '16 at 7:18
  • 1
    $\begingroup$ Show does work for overlaying two different graphics. Your problem might be, that ErrorListPlot and LogPlot have different coordinates - Log[y] vs y. So you need to implement logarithmic ErrorListPlot yourself. Check out Plotting Error Bars on a Log Scale. $\endgroup$ – Johu Jun 9 '16 at 7:27
1
$\begingroup$

I was able to make an interpolating function for my set of discrete points using the following code:

gfunc2 = Boole[
   10 < M < 13] ListInterpolation[{0.0003256, 0.0002971, 0.0002980, 
    0.0002757, 0.0002546, 0.0002400, 0.0002253, 0.0002015, 0.0001900, 
    0.0001856, 0.0001750, 0.0001753, 0.0001732, 0.0001692, 0.0001630, 
    0.0001503, 0.0001309, 0.0001135, 0.00009117, 0.00007193, 
    0.00005419, 0.00003707, 0.00002439, 0.00001501, 0.000008719, 
    0.000004783, 0.000002529, 0.000001170, 0.0000004598, 0.0000001803,
     0.00000006044, 
    0.00000001651}, {{8.90, 9.00, 9.10, 9.20, 9.30, 9.40, 9.50, 9.60, 
     9.70, 9.80, 9.90, 10.00, 10.10, 10.20, 10.30, 10.40, 10.50, 
     10.60, 10.70, 10.80, 10.90, 11.00, 11.10, 11.20, 11.30, 11.40, 
     11.50, 11.60, 11.70, 11.80, 11.90, 12.00}}]

And then running the following code in which the analytical function and the interpolating function are put together and treated on the same footing:

With[{a=25},
LogPlot[{g[M], gfunc2[M - Log10[a]]}, {M, 8, 16}, PlotRange -> {10^-17., 10.}, 
     PlotStyle -> {Black, Blue, Thick}, 
     Frame -> True, 
     FrameLabel -> {Style["Log(M)", FontSize -> 30], Style["Y-axis Log Scale", FontSize -> 30]}, 
     FrameTicksStyle -> Directive[FontSize -> 30], 
     PlotLegend -> {Style["first function", 20], Style["second function", 20]}]]

This actually produced the plot I was looking for. However, I still don't know how to do the job for an interval rather than a fixed value for $a$.

$\endgroup$
  • $\begingroup$ However, I need to show the data points (central values and error bars) rather than an interpolating function along side a continuous function on the same plot. I still don't know how to combine these two formats. $\endgroup$ – Benjamin Jul 14 '16 at 17:09

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.