working on background color; hexbin/heatmap; started test_plottypes
This commit is contained in:
parent
88a4b5cd12
commit
8ff438763b
@ -42,6 +42,12 @@ type Plot
|
||||
n::Int # number of series
|
||||
end
|
||||
|
||||
Base.string(plt::Plot) = "Plot{$(plt.plotter) n=$(plt.n)}"
|
||||
Base.print(io::IO, plt::Plot) = print(io, string(plt))
|
||||
Base.show(io::IO, plt::Plot) = print(io, string(plt))
|
||||
|
||||
|
||||
# ---------------------------------------------------------
|
||||
|
||||
type CurrentPlot
|
||||
nullableplot::Nullable{Plot}
|
||||
|
||||
34
src/args.jl
34
src/args.jl
@ -7,7 +7,7 @@ const NUMCOLORS = length(COLORS)
|
||||
|
||||
# these are valid choices... first one is default value if unset
|
||||
const LINE_AXES = (:left, :right)
|
||||
const LINE_TYPES = (:line, :step, :stepinverted, :sticks, :dots, :none, :heatmap, :hist, :bar)
|
||||
const LINE_TYPES = (:line, :step, :stepinverted, :sticks, :dots, :none, :heatmap, :hexbin, :hist, :bar)
|
||||
const LINE_STYLES = (:solid, :dash, :dot, :dashdot, :dashdotdot)
|
||||
const LINE_MARKERS = (:none, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon)
|
||||
|
||||
@ -27,6 +27,7 @@ PLOT_DEFAULTS[:markercolor] = :match
|
||||
PLOT_DEFAULTS[:markersize] = 10
|
||||
PLOT_DEFAULTS[:heatmap_n] = 100
|
||||
PLOT_DEFAULTS[:heatmap_c] = (0.15, 0.5)
|
||||
PLOT_DEFAULTS[:fillto] = nothing # fills in the area
|
||||
|
||||
# plot globals
|
||||
PLOT_DEFAULTS[:title] = ""
|
||||
@ -34,7 +35,7 @@ PLOT_DEFAULTS[:xlabel] = ""
|
||||
PLOT_DEFAULTS[:ylabel] = ""
|
||||
PLOT_DEFAULTS[:yrightlabel] = ""
|
||||
PLOT_DEFAULTS[:legend] = true
|
||||
PLOT_DEFAULTS[:background_color] = :white
|
||||
# PLOT_DEFAULTS[:background_color] = nothing
|
||||
PLOT_DEFAULTS[:xticks] = true
|
||||
PLOT_DEFAULTS[:yticks] = true
|
||||
|
||||
@ -56,11 +57,11 @@ autocolor(idx::Integer) = COLORS[mod1(idx,NUMCOLORS)]
|
||||
|
||||
# converts a symbol or string into a colorant (Colors.RGB), and assigns a color automatically
|
||||
# note: if plt is nothing, we aren't doing anything with the color anyways
|
||||
function getRGBColor(c, plt)
|
||||
function getRGBColor(c, n::Int = 0)
|
||||
|
||||
# auto-assign a color based on plot index
|
||||
if c == :auto
|
||||
c = autocolor(plt.n)
|
||||
if c == :auto && n > 0
|
||||
c = autocolor(n)
|
||||
end
|
||||
|
||||
# convert it from a symbol/string
|
||||
@ -83,6 +84,14 @@ function getPlotKeywordArgs(kw, i::Int, plt = nothing)
|
||||
d = Dict(kw)
|
||||
outd = Dict()
|
||||
|
||||
# default to a white background, but only on the initial call (so we don't change the background automatically)
|
||||
if haskey(d, :background_color)
|
||||
outd[:background_color] = getRGBColor(d[:background_color])
|
||||
elseif plt == nothing
|
||||
d[:background_color] = colorant"white"
|
||||
end
|
||||
|
||||
# fill in outd with either 1) plural value, 2) value, 3) default
|
||||
for k in keys(PLOT_DEFAULTS)
|
||||
plural = makeplural(k)
|
||||
if haskey(d, plural)
|
||||
@ -94,26 +103,17 @@ function getPlotKeywordArgs(kw, i::Int, plt = nothing)
|
||||
end
|
||||
end
|
||||
|
||||
# once the plot is created, we can get line/marker colors
|
||||
if plt != nothing
|
||||
# update color
|
||||
outd[:color] = getRGBColor(outd[:color], plt)
|
||||
outd[:color] = getRGBColor(outd[:color], plt.n)
|
||||
|
||||
# update markercolor
|
||||
mc = outd[:markercolor]
|
||||
mc = (mc == :match ? outd[:color] : getRGBColor(mc, plt))
|
||||
mc = (mc == :match ? outd[:color] : getRGBColor(mc, plt.n))
|
||||
outd[:markercolor] = mc
|
||||
end
|
||||
|
||||
# # auto assign a color
|
||||
# if plt != nothing
|
||||
# if outd[:color] == :auto
|
||||
# outd[:color] = autocolor(plt.n)
|
||||
# end
|
||||
# if outd[:markercolor] == :auto
|
||||
# outd[:markercolor] = outd[:color]
|
||||
# end
|
||||
# end
|
||||
|
||||
outd
|
||||
end
|
||||
|
||||
|
||||
@ -7,56 +7,67 @@ immutable GadflyPackage <: PlottingPackage end
|
||||
# create a blank Gadfly.Plot object
|
||||
function plot(pkg::GadflyPackage; kw...)
|
||||
@eval import DataFrames
|
||||
|
||||
plt = Gadfly.Plot()
|
||||
plt.mapping = Dict()
|
||||
plt.data_source = DataFrames.DataFrame()
|
||||
plt.layers = plt.layers[1:0]
|
||||
|
||||
# add the title, axis labels, and theme
|
||||
d = Dict(kw)
|
||||
plt.guides = Gadfly.GuideElement[Gadfly.Guide.xlabel(d[:xlabel]), Gadfly.Guide.ylabel(d[:ylabel]), Gadfly.Guide.title(d[:title])]
|
||||
plt.theme = Gadfly.Theme(background_color = (haskey(d, :background_color) ? d[:background_color] : colorant"white"))
|
||||
# key_position = (d[:legend] ? :bottom : :none))
|
||||
|
||||
Plot(plt, pkg, 0)
|
||||
end
|
||||
|
||||
|
||||
|
||||
# note: currently only accepts lines and dots
|
||||
function getGeomLine(linetype::Symbol)
|
||||
linetype == :line && return [Gadfly.Geom.line]
|
||||
linetype == :dots && return [Gadfly.Geom.point]
|
||||
function getGeoms(linetype::Symbol, marker::Symbol, heatmap_n::Int)
|
||||
geoms = []
|
||||
if linetype in (:heatmap,:hexbin)
|
||||
push!(geoms, Gadfly.Geom.hexbin(xbincount=heatmap_n, ybincount=heatmap_n))
|
||||
else
|
||||
if linetype == :line
|
||||
push!(geoms, Gadfly.Geom.line)
|
||||
elseif linetype == :dots || marker != :none
|
||||
push!(geoms, Gadfly.Geom.point)
|
||||
elseif linetype != :dots
|
||||
error("linetype $linetype not currently supported with Gadfly")
|
||||
end
|
||||
|
||||
# note: currently map any marker to point
|
||||
function getGeomPoint(marker::Symbol)
|
||||
marker == :none && return []
|
||||
[Gadfly.Geom.point]
|
||||
end
|
||||
end
|
||||
|
||||
# # note: currently only accepts lines and dots
|
||||
# function getGeomLine(linetype::Symbol, heatmap_n::Int)
|
||||
# linetype == :line && return [Gadfly.Geom.line]
|
||||
# linetype == :dots && return [Gadfly.Geom.point]
|
||||
# linetype in (:heatmap, :hexbin) && return [Gadfly.Geom.hexbin(xbincount=heatmap_n, ybincount=heatmap_n)]
|
||||
# error("linetype $linetype not currently supported with Gadfly")
|
||||
# end
|
||||
|
||||
# # note: currently map any marker to point
|
||||
# function getGeomPoint(linetype::Syombol, marker::Symbol)
|
||||
# if marker == :none || linetype in (:heatmap, :hexbin)
|
||||
# return []
|
||||
# end
|
||||
# [Gadfly.Geom.point]
|
||||
# end
|
||||
|
||||
# plot one data series
|
||||
function plot!(::GadflyPackage, plt::Plot; kw...)
|
||||
d = Dict(kw)
|
||||
|
||||
gfargs = []
|
||||
# append!(gfargs, getGeomLine(d[:linetype], d[:heatmap_n]))
|
||||
# append!(gfargs, getGeomPoint(d[:marker]))
|
||||
append!(gfargs, getGeoms(d[:linetype], d[:marker], d[:heatmap_n]))
|
||||
|
||||
append!(gfargs, getGeomLine(d[:linetype]))
|
||||
append!(gfargs, getGeomPoint(d[:marker]))
|
||||
theme = Gadfly.Theme(default_color = d[:color],
|
||||
line_width = d[:width] * Gadfly.px,
|
||||
default_point_size = d[:markersize] * Gadfly.px)
|
||||
push!(gfargs, theme)
|
||||
|
||||
|
||||
# todo:
|
||||
# linestyle
|
||||
# label
|
||||
|
||||
# # color
|
||||
# c = d[:color]
|
||||
# if isa(c, Symbol)
|
||||
# c = string(c)
|
||||
# end
|
||||
# if isa(c, String)
|
||||
# c = parse(Colorant, c)
|
||||
# end
|
||||
# @assert isa(c, RGB)
|
||||
push!(gfargs, Gadfly.Theme(default_color = d[:color]))
|
||||
|
||||
# legend
|
||||
# guides (x/y labels, title, background, ticks)
|
||||
|
||||
append!(plt.o.layers, Gadfly.layer(unique(gfargs)...; x = d[:x], y = d[:y]))
|
||||
plt
|
||||
end
|
||||
|
||||
23
src/qwt.jl
23
src/qwt.jl
@ -3,9 +3,30 @@
|
||||
|
||||
immutable QwtPackage <: PlottingPackage end
|
||||
|
||||
plot(pkg::QwtPackage; kw...) = Plot(Qwt.plot(zeros(0,0); kw...), pkg, 0)
|
||||
function adjustQwtKeywords(; kw...)
|
||||
d = Dict(kw)
|
||||
if d[:linetype] == :hexbin
|
||||
d[:linetype] = :heatmap
|
||||
end
|
||||
d
|
||||
end
|
||||
|
||||
function plot(pkg::QwtPackage; kw...)
|
||||
kw = adjustQwtKeywords(;kw...)
|
||||
plt = Plot(Qwt.plot(zeros(0,0); kw..., show=false), pkg, 0)
|
||||
# d = Dict(kw)
|
||||
# if haskey(d, :background_color)
|
||||
# Qwt.background!(plt.o, Dict(kw)[:background_color])
|
||||
# end
|
||||
plt
|
||||
end
|
||||
|
||||
function plot!(::QwtPackage, plt::Plot; kw...)
|
||||
kw = adjustQwtKeywords(;kw...)
|
||||
# d = Dict(kw)
|
||||
# if haskey(d, :background_color)
|
||||
# Qwt.background!(plt.o, Dict(kw)[:background_color])
|
||||
# end
|
||||
Qwt.oplot(plt.o; kw...)
|
||||
end
|
||||
|
||||
|
||||
13
test/test_plottypes.jl
Normal file
13
test/test_plottypes.jl
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
|
||||
function testplot_line1()
|
||||
plot(rand(100,3))
|
||||
end
|
||||
|
||||
function testplot_fn1()
|
||||
plot(0:0.01:4π, [sin,cos])
|
||||
end
|
||||
|
||||
function testplot_guides1()
|
||||
plot(rand(10); title="TITLE", xlabel="XLABEL", ylabel="YLABEL", background_color=:red)
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user