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.

Tooltip works fine in ListPlot:

ListPlot[Table[Tooltip[PDF[PoissonDistribution[10], x]], {x, 0, 20}]]

in which the decimal value of the distribution at a point is revealed when a cursor is placed over that data point.

How does one get the same functionality using DiscretePlot? For instance,

DiscretePlot[Tooltip[PDF[PoissonDistribution[10], x]], {x, 0, 20}]

reveals "PDF[PoissonDistribution[10], x]" (rather than the desired numerical value) when a cursor is placed over a data point.

I've tried a number of obvious alternatives, such as Tooltip with two arguments and Evaluate or N (numerical value) applied to the PDF. None work.

share|improve this question

2 Answers 2

up vote 9 down vote accepted

Here's a quick fix:

DiscretePlot[
  Tooltip[PDF[PoissonDistribution[10], x]]
  , {x, 0, 20}] /. Tooltip[a_, b_] :> Map[Tooltip[Point[#], Last@#] &, a[[3, 1]]]

If you investigate under the hood,

Cases[
  ListPlot[Table[Tooltip[PDF[PoissonDistribution[10], x]], {x, 0, 1}]]
  , Tooltip[a__] :> {a}
  , Infinity]
(* { {{Opacity[0.], Point[{{1., 0.0000453999}}]}, 0.0000453999}
     , {{Opacity[0.], Point[{{2., 0.000453999}}]}, 0.000453999} } *)

so that each point gets its own Tooltip labeled with the value, whereas

Cases[DiscretePlot[Tooltip[PDF[PoissonDistribution[10], x]], {x, 0, 1}]
  , Tooltip[a__] :> a
  , Infinity]
(* {{{}, Null, Point[{{0., 0.0000453999}, {1., 0.000453999}}], {}}
     , PDF[PoissonDistribution[10],x]} *)

In DiscretePlot, the second argument of Tooltip is PDF[PoissonDistribution[10],x], which means each point will be labeled with that expression. I do not know why it does this.

share|improve this answer
    
Thanks. Your quick fix suffices. Solution accepted. (I wish there were a more elegant solution, however.) –  David G. Stork 6 hours ago
    
@DavidG.Stork. There might be! ciao very briefly had a comment with something that almost seemed to work, so perhaps something along those lines might work. As far as Tooltip and DiscretePlot working together nicely, who knows if there's correct syntax for that. I tend for quick fixes and kluges if it's not too inelegant. –  march 6 hours ago
1  
@march: Yes, that was thiiiisss close, eh? Afraid it was a dead end, your method seems sound (upvoted it and question). Perhaps one of the deep evaluation spelunkers here can enlighten why one can't get at the evaluated value for use in tooltip, or a way to do it... –  ciao 4 hours ago

THIS IS NOT AN ANSWER BUT RATHER AN EXTENDED COMMENT.

Your ListPlot example is shifted from the proper location since the data is assumed to start with 1 rather than 0. To correct this, you can either enter data points or specify the DataRange. You can use the option Filling->Axis to get the same format as you would with DiscretePlot.

ListPlot[
 Tooltip[PDF[PoissonDistribution[10], #]] & /@ Range[0, 20], 
 DataRange -> {0, 20}, Filling -> Axis]

enter image description here

share|improve this answer
    
Yes. You are correct about the unit offset. –  David G. Stork 6 hours ago
    
Excellent! Going meta. –  march 6 hours ago

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.