2
$\begingroup$

I have a plot that I would like to make it like a ListPlot with joined lines. I mean, for each integer ‘k’, I want to have a dot over each line.

Here is the simplified plot:

γ = 50;
F[n_] := 1 + n (23 γ) + 154;

Ftotal[n_, k_] := k F[n] + (27);
Plot[{Ftotal[500, k], Ftotal[300, k]}, {k, 7, 12}, Frame -> True, 
 PlotRange -> All]

enter image description here

$\endgroup$
  • 2
    $\begingroup$ Have you seen the Mesh option of Plot[]? $\endgroup$ – J. M.'s discontentment Jun 6 at 7:50
  • $\begingroup$ @J.M.'stechnicaldifficulties Thanks you $\endgroup$ – sara samavati Jun 6 at 18:43
4
$\begingroup$
Show[
 Plot[{Ftotal[500, k], Ftotal[300, k]}, {k, 7, 12},
  Frame -> True, PlotRange -> All],
 ListPlot[Transpose@Table[{{k, Ftotal[500, k]},
     {k, Ftotal[300, k]}}, {k, 7, 12}]]]

Output

or since the lines are straight

ListLinePlot[Transpose@Table[{{k, Ftotal[500, k]},
    {k, Ftotal[300, k]}}, {k, 7, 12}],
 PlotMarkers -> Graphics[{PointSize[0.025], Point[{0, 0}]}],
 Frame -> True, PlotRange -> All]

Same output.

Also, plot with epilog

Plot[{Ftotal[500, k], Ftotal[300, k]}, {k, 7, 12},
 Frame -> True, PlotRange -> All, Epilog -> {PointSize[0.015],
   Transpose@Prepend[Map[Point, Table[
       {{k, Ftotal[500, k]}, {k, Ftotal[300, k]}}, {k, 7, 12}], {2}],
     {ColorData[97, 1], ColorData[97, 2]}]}]

Same output.

and as J. M.'s technical difficulties observes, use of Mesh

Plot[{Ftotal[500, k], Ftotal[300, k]}, {k, 7, 12},
 Frame -> True, PlotRange -> All,
 Mesh -> {Range[7, 12]}, MeshStyle -> PointSize[Medium]]

Output

but in this instance the end points are not plotted.

It works with the ListLinePlot version though.

ListLinePlot[Transpose@Table[{{k, Ftotal[500, k]},
    {k, Ftotal[300, k]}}, {k, 7, 12}],
 Frame -> True, PlotRange -> All,
 Mesh -> All, MeshStyle -> PointSize[Medium]]
| improve this answer | |
$\endgroup$
  • $\begingroup$ Awesome, thank you @chris $\endgroup$ – sara samavati Jun 6 at 18:33
  • $\begingroup$ Chris, why do you make it a point to specify “since the lines are straight” before you give a method using ListLinePlot? $\endgroup$ – CA Trevillian Jun 7 at 20:28
  • $\begingroup$ Hi. Because in plotting the integer results from Table any curve between the points would not be plotted. See this example : ListLinePlot[Transpose @ Table[{{k^16, Ftotal[500, k]}, {k^16, Ftotal[300, k]}}, {k, 4, 7}], PlotMarkers -> Graphics[{PointSize[0.025], Point[{0, 0}]}], Frame -> True, PlotRange -> All] $\endgroup$ – Chris Degnen Jun 7 at 20:38

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.