Opened 11 years ago
Last modified 5 years ago
#1893 needs_work enhancement
[with bundle, needs additional review] Added graphical plotting to discrete random variables.
Reported by:  kohel  Owned by:  boothby 

Priority:  minor  Milestone:  sage6.4 
Component:  graphics  Keywords:  
Cc:  Merged in:  
Authors:  Reviewers:  
Report Upstream:  N/A  Work issues:  
Branch:  Commit:  
Dependencies:  Stopgaps: 
Description (last modified by )
This example explains the functionality for the new function 'plot':
sage: import urllib2 sage: S = AlphabeticStrings() sage: ISARC = 'http://iml.univmrs.fr/~kohel/tch/ISARC/' sage: en = S.encoding(urllib2.urlopen(ISARC + 'blackcat.txt').read()) sage: F_en = en.frequency_distribution() sage: F_en.plot() sage: fr = S.encoding(urllib2.urlopen(ISARC + 'chapitre.1.txt').read()) sage: F_fr = fr.frequency_distribution() sage: F_fr.plot()
Unfortunately, I did not include such an example in the function since it hardcodes an external web address, and would otherwise require a reasonably sized sample text for a proper demonstration.
Attachments (1)
Change History (12)
Changed 11 years ago by
comment:1 Changed 11 years ago by
 Milestone set to sage2.10.1
comment:2 Changed 11 years ago by
 Summary changed from Added graphical plotting to discrete random variables. to [with bundle, needs review] Added graphical plotting to discrete random variables.
comment:3 Changed 11 years ago by
 Summary changed from [with bundle, needs review] Added graphical plotting to discrete random variables. to [with bundle, with positive review] Added graphical plotting to discrete random variables.
comment:4 Changed 11 years ago by
 Description modified (diff)
comment:5 Changed 11 years ago by
 Summary changed from [with bundle, with positive review] Added graphical plotting to discrete random variables. to [with bundle, needs additional review] Added graphical plotting to discrete random variables.
Nick raised some issue which should be addressed.
Cheers,
Michael
comment:6 Changed 9 years ago by
 Component changed from notebook to graphics
 Report Upstream set to N/A
According to hg in probabiity.hg p
in 4.3.1.rc0,

sage/probability/random_variable.py
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 b from sage.structure.parent_base import P 21 21 from sage.misc.functional import sqrt, log 22 22 from sage.rings.all import RealField, RationalField 23 23 from sage.sets.set import Set 24 import sage.plot.plot as plot 24 25 25 26 ################################################################################ 26 27 ################################################################################ … … class DiscreteRandomVariable(RandomVaria 265 266 "Correlation not defined if standard deviations are not both nonzero." 266 267 return cov/(sigX*sigY) 267 268 269 def plot(f, rgbcolor=(1,0,0)): 270 """ 271 Create a histogram from a frequency distribution or random variable. 272 """ 273 X = f.domain() 274 Text = [] 275 Bars = [] 276 fnc_max = 0.0 277 N = len(X) 278 for n in range(N): 279 x = X[n] 280 y = f(x) 281 fnc_max = max(fnc_max,y) 282 Text.append(plot.text(str(x),(n+0.5,0.01),rgbcolor = (0,0,0))) 283 Bars.append(plot.polygon([ [n,0], [n,y], [n+1,y], [n+1,0] ], rgbcolor = rgbcolor)) 284 Hist = sum(Text+Bars) 285 Hist.range(xmin=0,xmax=N,ymin=0,ymax=fnc_max) 286 return Hist 287
Does this belong in graphics?
comment:7 Changed 6 years ago by
 Milestone changed from sage5.11 to sage5.12
comment:8 Changed 5 years ago by
 Milestone changed from sage6.1 to sage6.2
comment:9 Changed 5 years ago by
 Milestone changed from sage6.2 to sage6.3
comment:10 Changed 5 years ago by
 Milestone changed from sage6.3 to sage6.4
comment:11 Changed 5 years ago by
I have a feeling that #9671 will address this sufficiently if one could plug it into the class in question.
Note: See
TracTickets for help on using
tickets.
This patch has been submitted (twice!) in the bundle accompanying #2153.
Whether it should be applied... I say yes, but I'm worried that it will fail on infinite domains.