4
$\begingroup$

How can I plot a function with one discrete and one continuous input? Plot3D wants everything continuous while ListPlot3D and ListPointPlot3D want everything discrete. I would like be able to say something like

HybridPlot[f[dsc, cnt], {dsc , min, max step}, {cnt, min max}]

or

HybridPlot[f[dsc, cnt], {dsc, someArray}, {cnt, min max}]

I am not seeing a simple way to do this in the docs.

$\endgroup$
1
  • 1
    $\begingroup$ Actually I think this is a duplicate of Plotting several functions. Heike's answer there is the same as the one I posted here. $\endgroup$
    – user484
    Commented Mar 28, 2014 at 0:21

2 Answers 2

6
$\begingroup$

If I understand the question correctly, you want to plot $f(a,x)$ as a function of $a$ and $x$, except that $a$ takes discrete values and $x$ lies in a continuous range. Maybe something like

f[a_, x_] := Exp[-x] x^(a - 1)/(a - 1)!

Then the graph of $f$ isn't a surface but a collection of curves $x\mapsto f(a,x)$, one for each discrete value of $a$. You could draw this using a parametric plot like

ParametricPlot3D[Evaluate@Table[{x, a, f[a, x]}, {a, 1, 5}], {x, 0, 10}, BoxRatios -> 1]

enter image description here

or maybe (this one is quite a hack)

ParametricPlot3D[Evaluate@Table[{x, a, z}, {a, 1, 5}], {x, 0, 10}, {z, 0, 0.5},
 RegionFunction -> Function[{x, a, z}, z < f[a, x]],
 BoxRatios -> 1, Mesh -> None, BoundaryStyle -> Black, MaxRecursion -> 5,
 Lighting -> {{"Ambient", LightGray}}]

enter image description here

$\endgroup$
2
  • $\begingroup$ How to adapt your solution to plot curves given by implicit equations? For example, the family of circles $x^2+y^2=r^2$ for $1\leq r \leq 2$ plotted at different heights with respect to the radius. $\endgroup$
    – Sigur
    Commented Mar 29, 2014 at 16:39
  • 1
    $\begingroup$ @Sigur: The second example will do the job; just replace the RegionFunction $z<f(a,x)$ with your implicit equation. $\endgroup$
    – user484
    Commented Mar 29, 2014 at 20:33
4
$\begingroup$

You can combine the plots with something like Show:

p1 = Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}, PlotRange -> {{-3, 3}, {-2, 2}, 
                                                                {-1, 1}}]
p2 =ListPlot3D[Flatten[Table[{x, y, Sin[-x + y^2] + .1}, {x, -3, 3, .1}, {y, -2, 
     2, .1}], 1], ColorFunction -> "SouthwestColors"]

Show[{p1, p2}]

You could also look at Prolog and Epilog to accomplish similar - lots of ways to skin this cat...

$\endgroup$

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