working on handling string input data
This commit is contained in:
parent
730d764c6e
commit
77d679b63b
@ -2,15 +2,42 @@
|
|||||||
"cells": [
|
"cells": [
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": 1,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"collapsed": false
|
"collapsed": false
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stderr",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"WARNING: Base.String is deprecated, use AbstractString instead.\n",
|
||||||
|
"WARNING: Base.String is deprecated, use AbstractString instead.\n",
|
||||||
|
"WARNING: Base.String is deprecated, use AbstractString instead.\n",
|
||||||
|
"INFO: Recompiling stale cache file /Users/tom/.julia/lib/v0.4/Plots.ji for module Plots.\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"[Plots.jl] Default backend: immerse"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stderr",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"WARNING: Base.None is deprecated, use Union{} instead.\n",
|
||||||
|
"WARNING: Base.None is deprecated, use Union{} instead.\n",
|
||||||
|
"WARNING: Base.None is deprecated, use Union{} instead.\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"using RDatasets, Plots; dataframes!()\n",
|
"using RDatasets, Plots; dataframes!()\n",
|
||||||
"iris = dataset(\"datasets\", \"iris\");\n",
|
"iris = dataset(\"datasets\", \"iris\");\n",
|
||||||
"plotDefault!(:size, (600,400));"
|
"plotDefault!(size=(600,400));"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -111,6 +138,85 @@
|
|||||||
"scatter([0,0],ms=40,m=:s)"
|
"scatter([0,0],ms=40,m=:s)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 3,
|
||||||
|
"metadata": {
|
||||||
|
"collapsed": false
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"ticks = ASCIIString[\"setosa\",\"versicolor\",\"virginica\"]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ename": "MethodError",
|
||||||
|
"evalue": "MethodError: `isless` has no method matching isless(::ASCIIString, ::Float64)\nClosest candidates are:\n isless(!Matched::Float64, ::Float64)\n isless(!Matched::AbstractFloat, ::AbstractFloat)\n isless(!Matched::Real, ::AbstractFloat)\n ...",
|
||||||
|
"output_type": "error",
|
||||||
|
"traceback": [
|
||||||
|
"MethodError: `isless` has no method matching isless(::ASCIIString, ::Float64)\nClosest candidates are:\n isless(!Matched::Float64, ::Float64)\n isless(!Matched::AbstractFloat, ::AbstractFloat)\n isless(!Matched::Real, ::AbstractFloat)\n ...",
|
||||||
|
""
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"bar(iris, :Species, :SepalLength)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"collapsed": false
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"bar(iris, :SepalLength, :Species)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"collapsed": false
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"findnext([1,2,1],1,4)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"collapsed": false
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"d = Dict(); get(d,:xticks,:auto)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"collapsed": false
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"issubtype(ASCIIString,ASCIIString)"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
@ -123,7 +229,7 @@
|
|||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"kernelspec": {
|
"kernelspec": {
|
||||||
"display_name": "Julia 0.4.0-rc1",
|
"display_name": "Julia 0.4.0-rc2",
|
||||||
"language": "julia",
|
"language": "julia",
|
||||||
"name": "julia-0.4"
|
"name": "julia-0.4"
|
||||||
},
|
},
|
||||||
|
|||||||
21
src/plot.jl
21
src/plot.jl
@ -105,8 +105,13 @@ function plot!(plt::Plot, args...; kw...)
|
|||||||
# now we can plot the series
|
# now we can plot the series
|
||||||
for (i,di) in enumerate(kwList)
|
for (i,di) in enumerate(kwList)
|
||||||
plt.n += 1
|
plt.n += 1
|
||||||
|
|
||||||
|
setTicksFromStringVector(d, di, :x, :xticks)
|
||||||
|
setTicksFromStringVector(d, di, :y, :yticks)
|
||||||
|
|
||||||
# println("Plotting: ", di)
|
# println("Plotting: ", di)
|
||||||
plot!(plt.plotter, plt; di...)
|
plot!(plt.plotter, plt; di...)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# add title, axis labels, ticks, etc
|
# add title, axis labels, ticks, etc
|
||||||
@ -122,6 +127,19 @@ function plot!(plt::Plot, args...; kw...)
|
|||||||
plt
|
plt
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function setTicksFromStringVector(d::Dict, di::Dict, sym::Symbol, ticksym::Symbol)
|
||||||
|
# if the x or y values are strings, set ticks to the unique values, and x/y to the indices of the ticks
|
||||||
|
# @show get(d,ticksym,:auto) == :auto isa(di[sym], AbstractArray) isa(eltype(di[sym]), AbstractString)
|
||||||
|
# @show get(d,ticksym,:auto) eltype(di[sym])
|
||||||
|
if get(d,ticksym,:auto) == :auto && isa(di[sym], AbstractArray) && issubtype(eltype(di[sym]), AbstractString)
|
||||||
|
ticks = unique(di[sym])
|
||||||
|
@show ticks
|
||||||
|
di[sym] = Int[findnext(ticks, v, 1) for v in di[sym]]
|
||||||
|
d[ticksym] = ticks
|
||||||
|
end
|
||||||
|
# @show sym ticksym di[sym] d[ticksym]
|
||||||
|
end
|
||||||
|
|
||||||
preparePlotUpdate(plt::Plot) = nothing
|
preparePlotUpdate(plt::Plot) = nothing
|
||||||
|
|
||||||
|
|
||||||
@ -155,6 +173,9 @@ convertToAnyVector(n::Integer; kw...) = Any[zero(0) for i in 1:n], nothing
|
|||||||
# numeric vector
|
# numeric vector
|
||||||
convertToAnyVector{T<:Real}(v::AVec{T}; kw...) = Any[v], nothing
|
convertToAnyVector{T<:Real}(v::AVec{T}; kw...) = Any[v], nothing
|
||||||
|
|
||||||
|
# string vector
|
||||||
|
convertToAnyVector{T<:AbstractString}(v::AVec{T}; kw...) = Any[v], nothing
|
||||||
|
|
||||||
# numeric matrix
|
# numeric matrix
|
||||||
convertToAnyVector{T<:Real}(v::AMat{T}; kw...) = Any[v[:,i] for i in 1:size(v,2)], nothing
|
convertToAnyVector{T<:Real}(v::AMat{T}; kw...) = Any[v[:,i] for i in 1:size(v,2)], nothing
|
||||||
|
|
||||||
|
|||||||
@ -133,6 +133,7 @@ end
|
|||||||
|
|
||||||
# ticksType{T<:Real,S<:Real}(ticks::Tuple{T,S}) = :limits
|
# ticksType{T<:Real,S<:Real}(ticks::Tuple{T,S}) = :limits
|
||||||
ticksType{T<:Real}(ticks::AVec{T}) = :ticks
|
ticksType{T<:Real}(ticks::AVec{T}) = :ticks
|
||||||
|
ticksType{T<:AbstractString}(ticks::AVec{T}) = :ticks
|
||||||
ticksType(ticks) = :invalid
|
ticksType(ticks) = :invalid
|
||||||
|
|
||||||
limsType{T<:Real,S<:Real}(lims::Tuple{T,S}) = :limits
|
limsType{T<:Real,S<:Real}(lims::Tuple{T,S}) = :limits
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user