-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
""" | ||
showdistribution([io], [mime], d) | ||
Show a UnicodePlots.barplot representation of a distribution. | ||
# Keyword Arguments | ||
- `title::String=string(typeof(d))*" distribution"`: title for the barplot. | ||
""" | ||
function showdistribution(io::IO, mime::MIME"text/plain", d; title=string(typeof(d))*" distribution") | ||
limited = get(io, :limit, false) | ||
strings = String[] | ||
probs = Float64[] | ||
|
||
rows = first(get(io, :displaysize, displaysize(io))) | ||
rows -= 6 # Yuck! This magic number is also in Base.print_matrix | ||
|
||
if limited && rows > 1 | ||
for (x,p) in Iterators.take(weighted_iterator(d), rows-1) | ||
push!(strings, sprint(show, x)) # maybe this should have conext=:compact=>true | ||
push!(probs, p) | ||
end | ||
|
||
push!(strings, "<everything else>") | ||
push!(probs, 1.0-sum(probs)) | ||
else | ||
for (x,p) in weighted_iterator(d) | ||
push!(strings, sprint(show, x)) | ||
push!(probs, p) | ||
end | ||
end | ||
show(io, mime, barplot(strings, probs, title=title)) | ||
end | ||
|
||
showdistribution(io::IO, d; kwargs...) = showdistribution(io, MIME("text/plain"), d; kwargs...) | ||
showdistribution(d; kwargs...) = showdistribution(stdout, d; kwargs...) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
d = SparseCat([1,2], [0.5, 0.5]) | ||
@test sprint(showdistribution, d) == " SparseCat{Array{Int64,1},Array{Float64,1}} distribution\n ┌ ┐ \n 1 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 0.5 \n 2 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 0.5 \n └ ┘ " | ||
|
||
d = SparseCat(1:50, fill(1/50, 50)) | ||
iob = IOBuffer() | ||
io = IOContext(iob, :limit=>true, :displaysize=>(10, 7)) | ||
showdistribution(io, d) | ||
@test String(take!(iob)) == " SparseCat{UnitRange{Int64},Array{Float64,1}} distribution\n ┌ ┐ \n 1 ┤■ 0.02 \n 2 ┤■ 0.02 \n 3 ┤■ 0.02 \n <everything else> ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 0.94 \n └ ┘ " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters