diff --git a/docs/example_generation.jl b/docs/example_generation.jl index d7369229..16cba2c0 100644 --- a/docs/example_generation.jl +++ b/docs/example_generation.jl @@ -157,8 +157,21 @@ const examples = PlotExample[ [ :(y = rand(10)), :(plot(y, ann=(3,y[3],text("this is #3",:left)))), - :(annotate!([(5,y[5],text("this is #5",16,:red,:center)),(10,y[10],text("this is #10",:right,20,"courier"))])) + :(annotate!([(5,y[5],text("this is #5",16,:red,:center)), + (10,y[10],text("this is #10",:right,20,"courier"))])) ]), + PlotExample("Custom Markers", + "A `Plots.Shape` is a light wrapper around vertices of a polygon. For supported backends, pass arbitrary polygons as the marker shapes. Note: The center is (0,0) and the size is expected to be rougly the area of the unit circle.", + [ + :(verts = [(-1.0,1.0),(-1.28,0.6),(-0.2,-1.4),(0.2,-1.4),(1.28,0.6),(1.0,1.0), + (-1.0,1.0),(-0.2,-0.6),(0.0,-0.2),(-0.4,0.6),(1.28,0.6),(0.2,-1.4), + (-0.2,-1.4),(0.6,0.2),(-0.2,0.2),(0.0,-0.2),(0.2,0.2),(-0.2,-0.6)]) + :(plot(0.1:0.2:0.9, 0.7rand(5)+0.15, + l=(3,:dash,:lightblue), + m=(Shape(verts),30,RGBA(0,0,0,0)), + bg=:pink, fg=:darkblue, + ylim=(0,1), leg=false)) + ]) ] diff --git a/src/args.jl b/src/args.jl index a069ae0f..4bd8d443 100644 --- a/src/args.jl +++ b/src/args.jl @@ -382,6 +382,9 @@ function processAxisArg(d::Dict, axisletter::@compat(AbstractString), arg) elseif T <: AVec d[symbol(axisletter * "ticks")] = arg + elseif arg == nothing + d[symbol(axisletter * "ticks")] = [] + else warn("Skipped $(axisletter)axis arg $arg") diff --git a/src/backends/gadfly.jl b/src/backends/gadfly.jl index 0da398ec..b32db77c 100644 --- a/src/backends/gadfly.jl +++ b/src/backends/gadfly.jl @@ -217,24 +217,26 @@ function getMarkerGeom(d::Dict) end -function getGadflyMarkerTheme(d::Dict) +function getGadflyMarkerTheme(d::Dict, initargs::Dict) c = getColor(d[:markercolor]) α = d[:markeropacity] if α != nothing c = RGBA(RGB(c), α) end + fg = getColor(initargs[:foreground_color]) Gadfly.Theme( default_color = c, default_point_size = d[:markersize] * Gadfly.px, # highlight_color = getColor(initargs[:foreground_color]), + discrete_highlight_color = c -> fg, highlight_width = d[:linewidth] * Gadfly.px, ) end -function addGadflyMarker!(plt::Plot, d::Dict, geoms...) +function addGadflyMarker!(plt::Plot, d::Dict, initargs::Dict, geoms...) gfargs = vcat(geoms..., - getGadflyMarkerTheme(d), + getGadflyMarkerTheme(d, initargs), getMarkerGeom(d)) kwargs = Dict() @@ -328,7 +330,7 @@ function addGadflySeries!(plt::Plot, d::Dict) # markers if d[:markershape] != :none - prepend!(layers, addGadflyMarker!(plt, d, smooth...)) + prepend!(layers, addGadflyMarker!(plt, d, plt.initargs, smooth...)) end lt in (:hist, :heatmap, :hexbin) || addToGadflyLegend(plt, d) @@ -367,10 +369,20 @@ end function addGadflyTicksGuide(gplt, ticks, isx::Bool) ticks == :auto && return + + # remove the ticks? + if ticks in (:none, false, nothing) + return addOrReplace(gplt.guides, isx ? Gadfly.Guide.xticks : Gadfly.Guide.yticks; label=false) + end + ttype = ticksType(ticks) + + # just the values... put ticks here, but use standard labels if ttype == :ticks gtype = isx ? Gadfly.Guide.xticks : Gadfly.Guide.yticks replaceType(gplt.guides, gtype(ticks = collect(ticks))) + + # set the ticks and the labels elseif ttype == :ticks_and_labels gtype = isx ? Gadfly.Guide.xticks : Gadfly.Guide.yticks replaceType(gplt.guides, gtype(ticks = collect(ticks[1]))) @@ -382,6 +394,7 @@ function addGadflyTicksGuide(gplt, ticks, isx::Bool) labelmap = Dict(zip(ticks...)) labelfunc = val -> labelmap[val] push!(gplt.scales, gfunc(levels = ticks[1], labels = labelfunc)) + else error("Invalid input for $(isx ? "xticks" : "yticks"): ", ticks) end diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 2b8a8f8f..2e4b34d4 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -63,7 +63,8 @@ supportedArgs(::PyPlotPackage) = [ supportedAxes(::PyPlotPackage) = _allAxes supportedTypes(::PyPlotPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline] supportedStyles(::PyPlotPackage) = [:auto, :solid, :dash, :dot, :dashdot] -supportedMarkers(::PyPlotPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :hexagon] +# supportedMarkers(::PyPlotPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :hexagon] +supportedMarkers(::GadflyPackage) = vcat(_allMarkers, Shape) supportedScales(::PyPlotPackage) = [:identity, :log, :log2, :log10] subplotSupported(::PyPlotPackage) = true @@ -87,6 +88,16 @@ function getPyPlotLineStyle(linetype::Symbol, linestyle::Symbol) return "-" end + +# function getMarkerGeom(d::Dict) +# shape = d[:markershape] +# gadflyshape(isa(shape, Shape) ? shape : _shapes[shape]) +# end + +function getPyPlotMarker(marker::Shape) + marker.vertices +end + # get the marker shape function getPyPlotMarker(marker::Symbol) marker == :none && return " " @@ -98,7 +109,11 @@ function getPyPlotMarker(marker::Symbol) marker == :cross && return "+" marker == :xcross && return "x" marker == :star5 && return "*" + marker == :pentagon && return "p" marker == :hexagon && return "h" + marker == :octagon && return "8" + haskey(_shapes, marker) && return _shapes[marker].vertices + warn("Unknown marker $marker") return "o" end