1
$\begingroup$

How to plot a function line with Markers:

f[x_, m_] = m Sin[x]
g[x_, m_] = 2 m Cos[x]
Manipulate[
 Plot[{f[x,m], g[x,m]}, {x, 0, 10}, 
  PlotLegends -> Automatic], {m, 0, 5}]

enter image description here

how to add markers like this automatic: enter image description here enter image description here

$\endgroup$
6
  • 1
    $\begingroup$ The question is vague. There seems to be no need for complicating it further with Manipulate. You can photoshop what marker you want and at which points perhaps. Thanks. $\endgroup$
    – Syed
    Commented Jan 17, 2023 at 8:02
  • $\begingroup$ @Syed I agree, when I first read this, I did not understand what the question meant. But I think they meant the Manipulate did not work. I could be wrong. $\endgroup$
    – Nasser
    Commented Jan 17, 2023 at 8:06
  • $\begingroup$ @Nasser, the OP has clarified it somewhat in the meantime, but I think that it is still not clear enough for a definitive answer. $\endgroup$
    – Syed
    Commented Jan 17, 2023 at 8:08
  • 2
    $\begingroup$ @Syed if you run the code they show as is (from clean kernel) you will notice the Manipulate does not work. So I have no idea how they obtained that screen shot. I am on V 13.2. $\endgroup$
    – Nasser
    Commented Jan 17, 2023 at 8:09
  • $\begingroup$ @Nasser I was under the impression that the author of the OP wanted to fix manipulate and change PlotMarkers at the same time. Anyway, I like your answer :-) $\endgroup$
    – bmf
    Commented Jan 17, 2023 at 8:10

2 Answers 2

4
$\begingroup$

Edit 3: please see below

f[x_, m_] := m Sin[x]
g[x_, m_] := 2 m Cos[x]
r0 = Table[{x, f[x, m]}, {x, 0, 10}];
r1 = Table[{x, g[x, m]}, {x, 0, 10}];
Manipulate[
 ListPlot[{r0, r1} /. m -> mm, 
  PlotMarkers -> {"\[FilledSquare]", "\[FilledCircle]"}, 
  Joined -> True, PlotRange -> {Automatic, {-5, 5}}, 
  InterpolationOrder -> 10], {mm, 1, 5}]

lp

Edit: thanks to @Syed

If I understand correctly something like the following:

f[x_, m_] := m Sin[x]
g[x_, m_] := 2 m Cos[x]

Manipulate[
 DiscretePlot[Evaluate[{f[x, m], g[x, m]}], {x, 0, 10}, 
  PlotRange -> {-10, 10}, Filling -> None, 
  PlotMarkers -> {{"\[FilledSquare]", 10}, {"\[FilledCircle]", 10}}, 
  PlotLegends -> "Expressions"], {m, 0, 5}]

Edit 2: connecting the points

Manipulate[
 DiscretePlot[Evaluate[{f[x, m], g[x, m]}], {x, 0, 10}, 
  PlotRange -> {-10, 10}, Filling -> None, 
  PlotMarkers -> {{"\[FilledSquare]", 10}, {"\[FilledCircle]", 10}}, 
  PlotLegends -> "Expressions", Joined -> True], {m, 0, 5}]
$\endgroup$
9
  • 1
    $\begingroup$ Add: , PlotRange -> {-10, 10} for visual benefit. $\endgroup$
    – Syed
    Commented Jan 17, 2023 at 8:11
  • $\begingroup$ @Syed you are absolutely right. Many thanks! $\endgroup$
    – bmf
    Commented Jan 17, 2023 at 8:12
  • $\begingroup$ This plot Discrete Points, but without lines about function, I want keep lines. $\endgroup$ Commented Jan 17, 2023 at 8:13
  • $\begingroup$ @ChinChingCHAN see the edit please $\endgroup$
    – bmf
    Commented Jan 17, 2023 at 8:16
  • $\begingroup$ @bmf The line seems not smoothly. $\endgroup$ Commented Jan 17, 2023 at 8:19
3
$\begingroup$

I am not sure if this is what you meant or not. (I assumed you meant your Manipulate was not working). Will delete if not.

enter image description here

f[x_, m_] := m Sin[x]
g[x_, m_] := 2 m Cos[x]
Manipulate[
 Plot[{f[x, m], g[x, m]}, {x, 0, 10}, PlotLegends -> Automatic, 
  PlotRange -> {Automatic, {-5, 5}}],
 {m, 0, 5},
 TrackedSymbols :> {m}]

The reason Manipulate did not work, is because m did not show in the expression. The control variable must show in the expression for it to work.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.