Skip to content

Commit

Permalink
update stats.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
sswatson committed Sep 30, 2020
1 parent 7acd693 commit 1639e05
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/stats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ function piechart(labels,frequencies; title="")
error("Labels and frequencies should have the same length")
end
angles = [[0];cumsum(2π*frequencies/sum(frequencies))]
fontsizes = [min(12,round(Integer;digits=50*(angles[i+1]-angles[i]))) for i=1:length(angles)-1]
fontsizes = [min(12,round(Integer, 50*(angles[i+1]-angles[i]))) for i=1:length(angles)-1]
Random.seed!(1)
sectors = [sector(1,angles[i],angles[i+1];
fillpen=Pen(color=ColorTypes.RGB(rand(),rand(),rand()),opacity=0.4))
for i=1:length(angles)-1]
text = [Label("$(labels[i]) ($(string(frequencies[i])))",(1+fontsizes[i]/60)*cis(mean([angles[i],angles[i+1]]));
text = [Label("$(labels[i]) ($(string(frequencies[i])))",(1+fontsizes[i]/60)*cis(Statistics.mean([angles[i],angles[i+1]]));
fontsize=fontsizes[i]) for i=1:length(angles)-1]
if title == ""
return Plot(sectors) + Plot(text;width=512)
Expand All @@ -67,7 +67,7 @@ function piechart(labels,frequencies; title="")
end

function sector(r,θ1,θ2;kwargs...)
arc = [r*cis(θ) for θ=linspace(θ1,θ2,500)[2:end-1]]
arc = [r*cis(θ) for θ=range(θ1,stop=θ2,length=500)[2:end-1]]
vee = [r*cis(θ2),0,r*cis(θ1)]
Polygon(vcat(arc,vee);kwargs...)
end

0 comments on commit 1639e05

Please sign in to comment.