2

Suppose I have two list,

list = {{1, 2, 3, 5, 6, 6.5, 7, 8, 9, 10}, {12, 10, 10, 10, 12, 10, 11, 11, 10, 11}}
list2 = {{1.2, 3, 3.5, 5.5, 6.2, 6.5, 7.8, 9, 10}, {12, 10, 10, 10, 12, 10, 11, 11, 10}}

If I plot it,

a1 = ListPlot[{Transpose[list], Transpose[list2]}, PlotRange -> {0, 20}, Joined -> True]

enter image description here

I do want to add this plot, then I did

f = Interpolation[Transpose[list]]
g = Interpolation[Transpose[list2]]

and I got

Plot[f[x] + g[x], {x, 1, 10}]

enter image description here

But When I try with little big data, it is very slow process. Is it the best way to combine the two list plot? or do we have some buildin code?

Saesun Kim
  • 1,810
  • 13
  • 24
  • 1
    Honestly this seems a pretty reasonable way to do what you want. The only thing you might consider is to use ListLinePlot[Transpose[list]] to generate the plots of the original lists, rather than plotting the interpolating functions. – MarcoB Feb 01 '16 at 18:04

1 Answers1

2

This one is much faster then Plot (but the use depends on your quality needs)

Graphics[Line@Transpose[{#, f[#] + g[#]}]] & @ Range[1.2, 10, 0.01];

enter image description here

Show[
 ListLinePlot[{Transpose[list], Transpose[list2]}, 
  PlotRange -> {0, 30}],
 Graphics[Line@Transpose[{#, f[#] + g[#]}]] &@Range[1.2, 10, 0.1]
 ]

Some note on time

Plot[f[x] + g[x], {x, 1.2, 10}]; // RepeatedTiming
(* {0.018, Null} *)

Graphics[Line@Transpose[{#, f[#] + g[#]}]] & @ Range[1.2, 10, 0.01]; // RepeatedTiming
(* {0.0037, Null}*)
garej
  • 4,865
  • 2
  • 19
  • 42