Skip to content

Commit 1497cae

Browse files
committed
Added histogram/etc functions for arrays, dicts
1 parent 96a2731 commit 1497cae

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ julia> Plotly.plot(wavread("filename.wav"))
106106
Using the WAV package, you can plot WAV files by passing a call to the `wavread` function.
107107

108108
# Detailed Plotting
109+
## Arrays and Dicts
110+
```julia
111+
julia> trace1 = Plotly.line([3x for x in 1:1000])
112+
julia> trace2 = Plotly.histogram([3x for x in 1:1000])
113+
julia> trace3 = Plotly.scatter([2x => 3x for x in 1:1000])
114+
julia> trace4 = Plotly.box([2x => 3x for x in 1:1000])
115+
julia
116+
```
117+
109118
## Functions and Polynomials
110119
```julia
111120
julia> trace1 = Plotly.line(abs, ["left"=>10, "right"=>20, "step"=>0.1])

src/plot.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,21 @@ function get_points(f::Function, options=Dict())
2020
end
2121
end
2222

23+
scatter(f::Array, options=Dict()) = {"type"=>"scatter","mode"=>"markers", "x"=>[1:length(f)], "y"=>f}
24+
line(f::Array, options=Dict()) = {"type"=>"scatter","mode"=>"lines", "x"=>[1:length(f)], "y"=>f}
25+
box(f::Array, options=Dict()) = {"type"=>"box", "x"=>[1:length(f)], "y"=>f}
26+
histogram(f::Array, options=Dict()) = {"type"=>"histogram", "x"=>[1:length(f)], "y"=>f}
27+
28+
scatter(f::Dict, options=Dict()) = {"type"=>"scatter","mode"=>"markers", "x"=>[k for k in keys(f)], "y"=>[v for v in Base.values(f)]}
29+
line(f::Dict, options=Dict()) = {"type"=>"scatter","mode"=>"lines", "x"=>[k for k in keys(f)], "y"=>[v for v in Base.values(f)]}
30+
box(f::Dict, options=Dict()) = {"type"=>"box", "x"=>[k for k in keys(f)], "y"=>[v for v in Base.values(f)]}
31+
histogram(f::Dict, options=Dict()) = {"type"=>"histogram", "x"=>[k for k in keys(f)], "y"=>[v for v in Base.values(f)]}
32+
2333
scatter(f::Function, options=Dict()) = get_points(f, merge({"type"=>"scatter","mode"=>"markers"}, options))
2434
line(f::Function, options=Dict()) = get_points(f, merge({"type"=>"scatter","mode"=>"lines"}, options))
2535
box(f::Function, options=Dict()) = get_points(f, merge({"type"=>"box"}, options))
2636
histogram(f::Function, options=Dict()) = get_points(f, merge({"type"=>"histogram"}, options))
37+
2738
plot(f::Function, options=Dict()) = plot([line(f, options)])
2839
plot(fs::Array{Function,1}, options=Dict()) = plot([line(f, options) for f in fs])
2940

0 commit comments

Comments
 (0)