working on spy and nbins tuple

This commit is contained in:
Thomas Breloff 2015-10-04 21:39:32 -05:00
parent 7c8898158b
commit 78045fd2ab
5 changed files with 129 additions and 5 deletions

107
examples/spy.ipynb Normal file
View File

@ -0,0 +1,107 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[Plots.jl] Default backend: immerse"
]
}
],
"source": [
"using Plots\n",
"n = 1000\n",
"a = rand(n)\n",
"y = Float64[i*a[i]+j*a[j] for i in 1:n, j in 1:n]\n",
"y = float(y .> mean(y));"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"[Plots.jl] Initializing backend: immerse"
]
}
],
"source": [
"spy(y, nbins=(20,100))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# get the indices (I,J) and the values (V) of non-zero values in y\n",
"I,J,V = findnz(y);\n",
"# plot the J's vs the I's in a heatmap to recreate the spy call\n",
"heatmap(J,I)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"pyplot()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"histogram(randn(1000), "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 0.4.0-rc2",
"language": "julia",
"name": "julia-0.4"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "0.4.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@ -33,6 +33,8 @@ export
ohlc,
ohlc!,
spy,
title!,
xlabel!,
ylabel!,
@ -95,6 +97,11 @@ vline!(args...; kw...) = plot!(args...; kw..., linetype = :vline)
ohlc(args...; kw...) = plot(args...; kw..., linetype = :ohlc)
ohlc!(args...; kw...) = plot!(args...; kw..., linetype = :ohlc)
"Sparsity plot... heatmap of non-zero values of a matrix"
function spy{T<:Real}(y::AMat{T}; kw...)
I,J,V = findnz(y)
heatmap(J, I; leg=false, kw...)
end
title!(s::AbstractString) = plot!(title = s)
xlabel!(s::AbstractString) = plot!(xlabel = s)
@ -122,7 +129,6 @@ xticks!{T<:Real,S<:AbstractString}(plt::Plot, ticks::AVec{T}, labels::AVec{S})
yticks!{T<:Real,S<:AbstractString}(plt::Plot, ticks::AVec{T}, labels::AVec{S}) = plot!(plt; yticks = (ticks,labels))
annotate!(plt::Plot, anns) = plot!(plt; annotation = anns)
# ---------------------------------------------------------

View File

@ -85,12 +85,12 @@ function createGadflyPlotObject(d::Dict)
end
# function getGeoms(linetype::Symbol, marker::Symbol, markercolor::Colorant, nbins::Int)
function getLineGeoms(d::Dict)
lt = d[:linetype]
lt == :hexbin && return [Gadfly.Geom.hexbin(xbincount = d[:nbins], ybincount = d[:nbins])]
lt == :heatmap && return [Gadfly.Geom.histogram2d(xbincount = d[:nbins], ybincount = d[:nbins])]
lt == :hist && return [Gadfly.Geom.histogram(bincount = d[:nbins])]
xbins, ybins = maketuple(d[:nbins])
lt == :hexbin && return [Gadfly.Geom.hexbin(xbincount = xbins, ybincount = ybins)]
lt == :heatmap && return [Gadfly.Geom.histogram2d(xbincount = xbins, ybincount = ybins)]
lt == :hist && return [Gadfly.Geom.histogram(bincount = xbins)]
# lt == :none && return [Gadfly.Geom.path]
lt == :path && return [Gadfly.Geom.path]
# lt == :scatter && return [Gadfly.Geom.point]

View File

@ -95,6 +95,13 @@ function adjustQwtKeywords(plt::Plot{QwtPackage}, iscreating::Bool; kw...)
end
replaceLinetypeAlias(d)
for k in keys(d)
if haskey(_qwtAliases, k)
d[_qwtAliases[k]] = d[k]
end
end
d
end

View File

@ -107,6 +107,10 @@ end
makevec(v::AVec) = v
makevec{T}(v::T) = T[v]
"duplicate a single value, or pass the 2-tuple through"
maketuple(x::Real) = (x,x)
maketuple{T,S}(x::Tuple{T,S}) = x
function replaceAliases!(d::Dict, aliases::Dict)
for (k,v) in d