diff --git a/examples/iris.ipynb b/examples/iris.ipynb index 8cd021f3..c88f6a6b 100644 --- a/examples/iris.ipynb +++ b/examples/iris.ipynb @@ -2,15 +2,42 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "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": [ "using RDatasets, Plots; dataframes!()\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)" ] }, + { + "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", "execution_count": null, @@ -123,7 +229,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Julia 0.4.0-rc1", + "display_name": "Julia 0.4.0-rc2", "language": "julia", "name": "julia-0.4" }, diff --git a/src/args.jl b/src/args.jl index b31fb831..24138c36 100644 --- a/src/args.jl +++ b/src/args.jl @@ -120,8 +120,8 @@ _plotDefaults[:yrightlabel] = "" _plotDefaults[:legend] = true _plotDefaults[:background_color] = colorant"white" _plotDefaults[:foreground_color] = :auto -_plotDefaults[:xlims] = :auto -_plotDefaults[:ylims] = :auto +_plotDefaults[:xlims] = :auto +_plotDefaults[:ylims] = :auto _plotDefaults[:xticks] = :auto _plotDefaults[:yticks] = :auto _plotDefaults[:size] = (800,600) diff --git a/src/plot.jl b/src/plot.jl index f36b24f2..4b68ad39 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -105,8 +105,13 @@ function plot!(plt::Plot, args...; kw...) # now we can plot the series for (i,di) in enumerate(kwList) plt.n += 1 + + setTicksFromStringVector(d, di, :x, :xticks) + setTicksFromStringVector(d, di, :y, :yticks) + # println("Plotting: ", di) plot!(plt.plotter, plt; di...) + end # add title, axis labels, ticks, etc @@ -122,6 +127,19 @@ function plot!(plt::Plot, args...; kw...) plt 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 @@ -155,6 +173,9 @@ convertToAnyVector(n::Integer; kw...) = Any[zero(0) for i in 1:n], nothing # numeric vector convertToAnyVector{T<:Real}(v::AVec{T}; kw...) = Any[v], nothing +# string vector +convertToAnyVector{T<:AbstractString}(v::AVec{T}; kw...) = Any[v], nothing + # numeric matrix convertToAnyVector{T<:Real}(v::AMat{T}; kw...) = Any[v[:,i] for i in 1:size(v,2)], nothing diff --git a/src/utils.jl b/src/utils.jl index 37799a45..97a546fa 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -133,6 +133,7 @@ end # ticksType{T<:Real,S<:Real}(ticks::Tuple{T,S}) = :limits ticksType{T<:Real}(ticks::AVec{T}) = :ticks +ticksType{T<:AbstractString}(ticks::AVec{T}) = :ticks ticksType(ticks) = :invalid limsType{T<:Real,S<:Real}(lims::Tuple{T,S}) = :limits