3

I have made this nice figure in Mathematica:

enter image description here

Now I want to add the values from my text file mytextfile to a plot which I already rendered.

Is there any function I can use to add the a list of values to my already created plot?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
user49166
  • 31
  • 1

3 Answers3

1

Assume that you have your plot made.

Mathematica graphics

Click in the plot and copy it (ctrl-C).

Start a new cell in your notebook and type:

plot = 

and then paste (ctrl-V) the plot to the right of the equal sign

Mathematica graphics

Now the symbol plot will represent the image.

To plot them together with your data use Show.

Show[
 ListPlot[data, PlotStyle -> Black],
 plot
 ]

Mathematica graphics

Side note: If you are creating the plot make the assignment to plot when you create it. For example:

plot = Plot[fun[x], {x, 0, 3}, PlotStyle -> Red]
Jack LaVigne
  • 14,462
  • 2
  • 25
  • 37
0

In[1]:

SeedRandom[1]
points = RandomInteger[100, {100, 2}];
Dynamic@ListPlot[points]

Out[1]:

Mathematica graphics

In[2]:

newPoints = RandomInteger[100, {50, 2}];
points = Join[points, newPoints];

Out[1]:

Mathematica graphics

webcpu
  • 3,182
  • 12
  • 17
  • "[...] to my already created graph" – Kuba May 29 '17 at 20:37
  • I am not sure if they are the same person or in a same team. At least I have answered it once. The new question is how to update the plot but not how to import data from a text file. https://mathematica.stackexchange.com/questions/147082/plot-from-following-inputs/147084#147084 – webcpu May 29 '17 at 20:46
0

If, instead, adding points to an existing curve is desired (which is how I originally interpreted the question), do the following. For instance, with the plot

plt = Plot[85 + 1/x, {x, 0, 3}, PlotRange -> {84, 100}]

enter image description here

add points (chosen somewhat randomly, so that they stand out)

newpts = {{.5, 85}, {2., 90.}};
plt /. Line[z_] -> Line[Sort[Join[pts, newpts]]]

enter image description here

bbgodfrey
  • 61,439
  • 17
  • 89
  • 156