#1893: [with bundle, needs additional review] Added graphical plotting to
discrete
random variables.
---------------------------+------------------------------------------------
Reporter: kohel | Owner: boothby
Type: enhancement | Status: needs_work
Priority: minor | Milestone: sage-4.3.1
Component: graphics | Keywords:
Work_issues: | Author:
Upstream: N/A | Reviewer:
Merged: |
---------------------------+------------------------------------------------
Changes (by mpatel):
* component: notebook => graphics
* upstream: => N/A
Comment:
According to `hg in probabiity.hg -p` in 4.3.1.rc0,
{{{
#!diff
summary: Added plotting function for graphical display of a discrete
random variable.
diff --git a/sage/probability/random_variable.py
b/sage/probability/random_variable.py
--- a/sage/probability/random_variable.py
+++ b/sage/probability/random_variable.py
@@ -21,6 +21,7 @@ from sage.structure.parent_base import P
from sage.misc.functional import sqrt, log
from sage.rings.all import RealField, RationalField
from sage.sets.set import Set
+import sage.plot.plot as plot
################################################################################
################################################################################
@@ -265,6 +266,25 @@ class DiscreteRandomVariable(RandomVaria
"Correlation not defined if standard deviations are not
both nonzero."
return cov/(sigX*sigY)
+ def plot(f, rgbcolor=(1,0,0)):
+ """
+ Create a histogram from a frequency distribution or random
variable.
+ """
+ X = f.domain()
+ Text = []
+ Bars = []
+ fnc_max = 0.0
+ N = len(X)
+ for n in range(N):
+ x = X[n]
+ y = f(x)
+ fnc_max = max(fnc_max,y)
+ Text.append(plot.text(str(x),(n+0.5,-0.01),rgbcolor =
(0,0,0)))
+ Bars.append(plot.polygon([ [n,0], [n,y], [n+1,y], [n+1,0] ],
rgbcolor = rgbcolor))
+ Hist = sum(Text+Bars)
+ Hist.range(xmin=0,xmax=N,ymin=0,ymax=fnc_max)
+ return Hist
+
}}}
Does this belong in
[http://trac.sagemath.org/sage_trac/query?component=graphics&order=priority
graphics]?
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/1893#comment:6>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.