Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I would like to plot a continuous function with Plot with plot markers as if it were a ListPlot plot.

Simple example: I have

f[x_]:=x
Plot[f[x],{x,0,10}]

but for external reasons I need the figure to look like that of

ListPlot[Table[{x,f[x]},{x,0,10}]]

It works well. But imagine now my f[x] function contains several functions:

f[x_]:={x,x^2,x^3}

Plotting with plot is the same:

Plot[f[x],{x,0,10}]

However, the conversion to a set of points with Table is now complicated.

The question is: what would be the easiest way (the shortest code) to produce a plot marker plot for such f[x]? Can it be done directly with Plot without using ListPlot and Table ?

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

Perhaps this would help:

f[x_]:={x,x^2,x^3};
DiscretePlot[Evaluate[f[x]], {x, 0, 1, 0.1}, Filling -> None, 
 PlotMarkers -> {{"a", 5}, {"b", 10}, {"c", 15}}, 
 PlotLegends -> "Expressions", Frame -> True]

enter image description here

share|improve this answer
1  
Odd that PlotLegend does not print the symbols defined by PlotMarkers? –  bobthechemist Mar 21 at 12:15
    
@bobthechemist I could have made it do that but it is not default and just wanted to illustrate a way to 'discretize' as per q...legends always need some fiddling –  ubpdqn Mar 21 at 12:18
    
Thank you. Choosing this solution as the most natural one, although two others are also good. –  Szczypawka Mar 31 at 13:54
add comment

The DiscretePlot proposed by ubpdqn is a natural solution. You can, however, expand the discretization like the one you used ListPlot[Table[{x,f[x]},{x,0,10}]] on the list like this f[x_]:={x,x^2,x^3}. Indeed, this is your function:

f[x_] := {x, x^2, x^3};

Let us define a function making a list like the one you used, but a bit differently:

g[z_] := Table[{x, z}, {x, 0, 1, 0.1}];

Then the solution is

ListPlot[g /@ f[x], PlotMarkers -> Automatic]

The result should look like this: enter image description here

share|improve this answer
add comment

If you want to avoid using ListPlot all together, you can explore the Mesh option to Plot:

Plot[f[x], {x, 0, 1}, Mesh -> 20, MeshShading -> {None}]

Mathematica graphics

The same MeshStyle will be applied to each of the functions, making this solution somewhat limited. If you insist on a Plot solution, however, we can do something silly like this:

Show@{Plot[#[[1]], {x, 0, 1}, Mesh -> 20, MeshShading -> {None}, 
     MeshStyle -> #[[2]]] & /@ Transpose[{f[x], {Red, Green, Blue}}]}

Mathematica graphics

share|improve this answer
    
Which is which? ;) –  Kuba Mar 21 at 13:21
    
@Kuba Yeah, limitation to this approach. –  bobthechemist Mar 21 at 13:22
    
@kuba how's that :-) –  bobthechemist Mar 21 at 13:26
    
Works :) but can't compete for the shortest solution :P –  Kuba Mar 21 at 13:32
    
@Kuba, hence the reason you'll never see me on code golf –  bobthechemist Mar 21 at 13:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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