2
$\begingroup$

Code is as follows.

aSet1 = {0.05447969195001433`, {1.62844, 1.79419}};
aSet2 = {0.05448351166864853`, {1.63506, 1.78729}};
aSet3 = {0.054488286316941295`, {1.64428, 1.77771}};
aSet4 = {0.05449306096523404`, {1.65507, 1.76657}};
aSet5 = {0.05449783561352681`, {1.66863, 1.75266}};
aSet6 = {0.054502610261819566`, {1.68992, 1.73102}};
aSet7 = {0.05450356519147811`, {1.69803, 1.72284}};
aSet8 = {0.052521131220325465`, {1.03786, 2.5299}};
aSet9 = {0.042971834634811745`, {0.353918, 3.94334}};
aSet10 = {0.033422538049298026`, {0.102792, 4.96211}};
aSet11 = {0.023873241463784306`, {5.87487, 5.87487}};
aSet12 = {0.014323944878270583`, {6.74069, 6.74069}};
aSet13 = {0.00954929658551372`, {7.16397, 7.16397}};

Tck400 = {aSet1, aSet2, aSet3, aSet4, aSet5, aSet6, aSet7, aSet8, 
aSet9, aSet10, aSet11, aSet12, aSet13};

c400 = ListPlot[{Table[{Tck400[[ii, 2, 2]], Tck400[[ii, 1]]}, {ii, 1, 
 Length[Tck400]}], Table[{Tck400[[ii, 2, 1]], Tck400[[ii, 1]]}, {ii, 1, 
 Length[Tck400]}]}, Frame -> True, RotateLabel -> False, Axes -> False, PlotRange -> All}]

With the following output (plot label wasn't included above):

enter image description here

I would like to ditch the points and plot a line or somehow fit a line to this data. My only thought was changing the format of the data to simple (x,y) points. Anything yall think would be nicer? Thanks!

Here is my solution based on rhermans solution

Tck230 = {fSet1, fSet2, fSet3, fSet4, fSet5, fSet6, fSet7, fSet8, fSet9, fSet10, fSet11, fSet12, fSet13, fSet14, fSet15, fSet16};
line230 = SortBy[First]@Flatten[Distribute[Reverse@#, List] & /@ Tck230, 1];

enter image description here

Here is my solution based on user1066 solution

data230 = DeleteDuplicates[Catenate[{Table[{Tck230[[ii, 2, 2]], Tck230[[ii, 1]]}, {ii, 1, Length[Tck230]}], Table[{Tck230[[ii, 2, 1]], Tck230[[ii, 1]]}, {ii, 1, Length[Tck230]}]}]];
f230 = Interpolation@data230;
data230 // Plot[f230[x], {x, Min@(#[[All, 1]]), Max@(#[[All, 1]])}, PlotRange -> {{0, 7.5}, {0, 0.12}}, PlotStyle -> Red, Frame -> True, Axes -> False] &

This was done for all curves, and the following was done for the overlay as done above:

enter image description here

$\endgroup$
  • $\begingroup$ Have you tried LinearModelFit, FindFit, etc? $\endgroup$ – Hector Jul 23 '18 at 22:19
  • 1
    $\begingroup$ Duplicate? (22293) $\endgroup$ – Mr.Wizard Jul 24 '18 at 5:59
3
$\begingroup$

1. Joined -> True

If you just want to join the points:

With[
 {
  data = SortBy[First]@
    Flatten[Distribute[Reverse@#, List] & /@ Tck400, 1]
  },
 Show[
  ListPlot[
   data
   , PlotStyle -> Blue
   , InterpolationOrder -> 2
   , Joined -> True
   , PlotTheme -> "Scientific"
   , PlotRange -> All
   ]
  ]
 ]

Mathematica graphics

2. FindFormula

If you don't have a model, you can try to guess one using FindFormula

With[
 {
  data = SortBy[First]@
    Flatten[Distribute[Reverse@#, List] & /@ Tck400, 1]
  },
 Plot[
  Evaluate@FindFormula[data, x, SpecificityGoal -> "High"]
  , {x, Sequence @@ MinMax[data[[All, 1]]]}
  , PlotStyle -> Red
  , PlotRange -> {0, All}
  , PlotTheme -> "Scientific"
  ]
 ]

Mathematica graphics

$\endgroup$
  • $\begingroup$ Thank you good sir! :) $\endgroup$ – Lopey Tall Jul 24 '18 at 0:13
  • 1
    $\begingroup$ ListLinePlot is more canonical at this point and seems better supported, e.g. mathematica.stackexchange.com/a/58996/121 $\endgroup$ – Mr.Wizard Jul 24 '18 at 5:57
  • $\begingroup$ Wasn't the only difference considered a bug? @Mr.Wizard $\endgroup$ – rhermans Jul 24 '18 at 6:53
  • $\begingroup$ Well, yes, that case was a bug, but it supports my point that ListLinePlot received more development attention than Joined -> True. I did not mean to detract from your answer which I voted for. $\endgroup$ – Mr.Wizard Jul 24 '18 at 8:45
  • $\begingroup$ my code and subsequent plots have been greatly improved! Ill post my final product for anyone having a similar issue and would like to use @rhermans answer. $\endgroup$ – Lopey Tall Jul 24 '18 at 21:05
1
$\begingroup$
f = Interpolation@data;
data // Plot[f[x], {x, Min@(#[[All, 1]]), Max@(#[[All, 1]])}, 
PlotRange -> {{0, 7.5}, {0, 0.07}},
PlotStyle -> Red, 
Frame -> True, 
Axes -> False, 
FrameTicks -> {Subdivide[0, 7, 7], Subdivide[0.01, 0.06, 5]}] &

Mathematica graphics

 data = DeleteDuplicates[Catenate[{Table[{Tck400[[ii, 2, 2]], Tck400[[ii, 1]]}, {ii, 1, 
   Length[Tck400]}], Table[{Tck400[[ii, 2, 1]], Tck400[[ii, 1]]}, {ii, 1, 
   Length[Tck400]}]}]];

Edit

In response to the OP comment the curves thus far are not smooth, thus providing ammunition for his advisor, it might be better to fit the data to a specific model rather than use interpolation. Nevertheless, increasing the interpolation order to 4 (from the default of 3) does seem to improve things.

f = Interpolation[data, InterpolationOrder -> 4];
data // Plot[f[x], {x, Min@(#[[All, 1]]), Max@(#[[All, 1]])}, 
PlotRange -> {{0, 7.5}, {0, 0.07}}, PlotStyle -> Red, 
Frame -> True, Axes -> False, 
FrameTicks -> {Subdivide[0, 7, 7], Subdivide[0.01, 0.06, 5]}] &

Mathematica graphics

Note that the interpolation function may be used to calculate y-values, provided that the x-values are within the interpolation range. (Useful for a 'standard curve' situation?)

f@3.5

0.0464684

f /@ Subdivide[Min@data[[All, 1]], 7, 10]

{0.0334225, 0.0510192, 0.0543068, 0.0538228, 0.0507972, 0.0460776, 0.0403554, 0.0337375, 0.0266037, 0.0191165, 0.0114045}

$\endgroup$
  • $\begingroup$ My advisor (@rhermans was gievn credit) just scolded me on the fact that my plots arent smooth haha so thank you for this! $\endgroup$ – Lopey Tall Jul 25 '18 at 16:05
  • 1
    $\begingroup$ Thanks for the upvote. I am not getting many of those lately. All advisors worship at the alter of the smooth curve! $\endgroup$ – user1066 Jul 25 '18 at 16:50
  • $\begingroup$ hehe of course mate! now I get to say even more people helped me online! I will edit the question with my update based on your work right now :) $\endgroup$ – Lopey Tall Jul 25 '18 at 17:04

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.