0
$\begingroup$

I am trying to use the Manipulate function in Mathematica and want to plot an expression over a scatterplot of (x,y) data. I can programme the Manipulate function, but am unable to do this on the same axes as the scatterplot - any hints much appreciated

I want to plot this data and then use Manipulate to visually fit a curve to the data...

The code I have written for the Manipulate function is:

Manipulate[
 Plot[c*k*(x^(c - 1))/((1 + x^c)^(j)), {x, 0, 5}, 
  PlotRange -> {{0, 5}, {0, 10}}], {c, 0, 10}, {k, 0, 10}, {j, 0, 5}]

and I want to include a command so the following plot is included on the axes in the manipulate environment.

The following data plot is created with:

ListPlot[ddata, PlotRange -> {{-6, 6}, {0, 0.05}}, AxesOrigin -> {-6, 0}]

This is the scatterplot I want in the background...

ddata is given by:

ddata = First@ToExpression@Import["http://pastebin.com/raw.php?i=KwJSvA2r", "Data"];
$\endgroup$
  • $\begingroup$ I have added a plot of the data - but if I could give a complete example, I wouldn't need to ask the question! Hope this additional data clarifies my question? $\endgroup$ – hydrologist Jul 2 '14 at 11:24
  • $\begingroup$ I have added the code I have written already - but I can't find the relevant commands to plot my data on the same axes as the manipulated function - does this make more sense? (thank you for your queries) $\endgroup$ – hydrologist Jul 2 '14 at 11:33
  • $\begingroup$ Does this make it clearer? I realise I will need to add a coefficient in the analytic expression to get the height of the peak correct...! ddata is a set of 200 (x,y) data pairs... $\endgroup$ – hydrologist Jul 2 '14 at 11:38
2
$\begingroup$
ddata = First@ToExpression@Import[
     "http://pastebin.com/raw.php?i=KwJSvA2r", "Data"];
ddata = ddata /. {a_, b_} -> {a + 1.5, b};
backgraound = ListPlot[ddata,
  PlotRange -> {{-2, 5}, {0, 500}},
  AxesOrigin -> {-2, 0}]

Blockquote

Manipulate[
 Show[{backgraound,
   Plot[r (c k (x - a)^(-1 + c) (1 + (x - a)^c)^-j), {x, 0, 5}]},
  PlotRange -> {{-2, 5}, {0, 500}},
  AxesOrigin -> {-2, 0}],
 {c, 0, 10}, {k, 0, 10}, {j, 0, 5},
 {a, -2, 2}, {r, 30, 70}]

Blockquote

$\endgroup$
1
$\begingroup$

Like this?

ddata = First@ToExpression@Import["http://pastebin.com/raw.php?i=KwJSvA2r", "Data"];

points = ListPlot[ddata, PlotRange -> {{-5, 5}, {0, 100}}, Axes -> True];

Manipulate[
 Show[points, 
  Plot[c*k*(x^(c - 1))/((1 + x^c)^(j)), {x, 0, 50}, PlotStyle -> Red, 
   PlotRange -> {{0, 5}, {0, 100}}]], {c, 0, 10}, {k, 0, 10}, {j, 0, 5}]

enter image description here

$\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.