Message Boards Message Boards

How to run a line function through points

Posted 11 years ago
I have 2 sets of input, one that displays 3 points and the other that displays a line function.  Seperately they both work fine but I cannot figure out how to combine them so that the line function appears on the same graph as the points.

Here is the line function:

a = -0.3;

b = 2;
f[x_] = a x + b;

Plot[f[x],{x,0,5}, PlotStyle->{{Red,Thickness[0.015]}},  AxesLabel->{"x","f[x]"}]
And here are the points:
 globb1 = Graphics[{Green,PointSize[0.15], Point[{1,4}]}];
 globb2 = Graphics[{Green,PointSize[0.18], Point[{3,1.4}]}];
 globb3 = Graphics[{Green,PointSize[0.17], Point[{4.2, 2.3}]}];
 moregreenblobs =Show[globb1,globb2,globb3,PlotRange->{{0,5},{0,5}},
      Axes->True, AxesOrigin->{0,0}, AxesLabel->{"x","y"}]
POSTED BY: bill bluet
3 Replies
Try this:
a = -0.3;b=2;
f[x_]:=a x + b;
line=Plot[f[x],{x,0,5}, PlotStyle->{{Red,Thickness[0.015]}},  AxesLabel->{"x","f[x]"}];
points=Graphics[{Green,PointSize[0.15], Point[{1,4}],PointSize[0.18], Point[{3,1.4}],PointSize[0.17], Point[{4.2, 2.3}]}];
      Axes->True, AxesOrigin->{0,0}, AxesLabel->{"x","y"}]
this is what you get: 
POSTED BY: george
Welcome to Wolfram Community, Bill! Please note how your code was formatted in special code-blocks. This makes it easy to read it and copy it. Use Spikey button in the editor - see image below. If you could also upgrade your profile information - it'd be great!   

POSTED BY: Vitaliy Kaurov
Save the line plot,
plt = Plot[f[x], ....
and combine it with the dots,
Show[moregreenblobs, plt]
POSTED BY: Bruce Miller
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract