Skip to content

Commit 0b78c19

Browse files
committed
add PyPlot glue
1 parent e4989f5 commit 0b78c19

File tree

8 files changed

+391
-49
lines changed

8 files changed

+391
-49
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ before_install:
1515
script:
1616
- julia -e 'Pkg.init(); run(`ln -s $(pwd()) $(Pkg.dir("KernelDensity"))`); Pkg.pin("KernelDensity"); Pkg.resolve()'
1717
- julia -e 'using KernelDensity; @assert isdefined(:KernelDensity); @assert typeof(KernelDensity) === Module'
18-
- julia ./runtests.jl
18+
- julia test/runtests.jl

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ e.g. `boundary` now takes a tuple of tuples `((xlo,xhi),(ylo,yhi))`.
5757

5858
## Plotting
5959

60-
The [Winston.jl](https://github.com/nolta/Winston.jl) plotting package is currently
61-
supported. See
62-
[this notebook](http://nbviewer.ipython.org/github/JuliaStats/KernelDensity.jl/blob/master/examples/kde.ipynb)
63-
for an example.
60+
The [Winston.jl](https://github.com/nolta/Winston.jl) and
61+
[PyPlot.jl](https://github.com/stevengj/PyPlot.jl) plotting packages are
62+
currently supported. See the ijulia notebooks:
63+
* [Winston](http://nbviewer.ipython.org/github/JuliaStats/KernelDensity.jl/blob/master/examples/Winston.ipynb)
64+
* [PyPlot](http://nbviewer.ipython.org/github/JuliaStats/KernelDensity.jl/blob/master/examples/PyPlot.ipynb)
6465

6566
We plan to include support for other plotting packages: please file an issue
6667
if your favourite one is not yet available.

examples/PyPlot.ipynb

Lines changed: 334 additions & 0 deletions
Large diffs are not rendered by default.

examples/kde.ipynb renamed to examples/Winston.ipynb

Lines changed: 17 additions & 34 deletions
Large diffs are not rendered by default.

src/KernelDensity.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,7 @@ macro glue(pkg)
2222
end
2323

2424
@glue Winston
25+
@glue PyPlot
2526

2627
end # module
28+

src/glue/PyPlot.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import PyPlot
2+
3+
function PyPlot.plot(k::UnivariateKDE, args...; kwargs...)
4+
PyPlot.plot(k.x, k.density, args...; kwargs...)
5+
end
6+
7+
function PyPlot.contour(k::BivariateKDE, args...; kwargs...)
8+
PyPlot.contour(k.x, k.y, k.density', args...; kwargs...)
9+
end
10+
function PyPlot.plot_surface(k::BivariateKDE, args...; kwargs...)
11+
PyPlot.plot_surface(k.x, k.y, k.density', args...; kwargs...)
12+
end
13+
function PyPlot.surf(k::BivariateKDE, args...; kwargs...)
14+
PyPlot.surf(k.x, k.y, k.density', args...; kwargs...)
15+
end
16+
17+
function PyPlot.plot_wireframe(k::BivariateKDE, args...; kwargs...)
18+
PyPlot.plot_wireframe(k.x, k.y, k.density', args...; kwargs...)
19+
end
20+
21+
function PyPlot.imshow(k::BivariateKDE, args...; kwargs...)
22+
PyPlot.imshow(k.density', args...; origin="lower", extent=[extrema(k.x)...,extrema(k.y)...], kwargs...)
23+
end

src/glue/Winston.jl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
using Winston
2-
import Winston: plot, imagesc
1+
import Winston
32

4-
function plot(p::FramedPlot, k::UnivariateKDE, args...; kwargs...)
5-
plot(p, k.x, k.density, args...; kwargs...)
3+
function Winston.plot(p::Winston.FramedPlot, k::UnivariateKDE, args...; kwargs...)
4+
Winston.plot(p, k.x, k.density, args...; kwargs...)
65
end
76

8-
function plot(k::UnivariateKDE, args...; kwargs...)
9-
plot(Winston.ghf(), k, args...; kwargs...)
7+
function Winston.plot(k::UnivariateKDE, args...; kwargs...)
8+
Winston.plot(Winston.ghf(), k, args...; kwargs...)
109
end
1110

12-
function imagesc(k::BivariateKDE, clims::Winston.Interval; kwargs...)
13-
imagesc(extrema(k.x), reverse(extrema(k.y)), k.density', clims; kwargs...)
11+
function Winston.imagesc(k::BivariateKDE, clims::Winston.Interval; kwargs...)
12+
Winston.imagesc(extrema(k.x), reverse(extrema(k.y)), k.density', clims; kwargs...)
1413
end
15-
function imagesc(k::BivariateKDE; kwargs...)
16-
imagesc(k, (0.0,maximum(k.density)); kwargs...)
14+
function Winston.imagesc(k::BivariateKDE; kwargs...)
15+
Winston.imagesc(k, (0.0,maximum(k.density)); kwargs...)
1716
end
File renamed without changes.

0 commit comments

Comments
 (0)