gadfly marker fixes and examples

This commit is contained in:
Thomas Breloff 2015-09-15 13:08:04 -04:00
parent 8bfaa14edb
commit 1e2b3559f2
41 changed files with 42 additions and 106 deletions

View File

@ -132,7 +132,7 @@ end
# run it! # run it!
# note: generate separately so it's easy to comment out # note: generate separately so it's easy to comment out
# generate_markdown(:qwt) # generate_markdown(:qwt)
# generate_markdown(:gadfly) generate_markdown(:gadfly)
# @osx_only generate_markdown(:unicodeplots) # @osx_only generate_markdown(:unicodeplots)
# generate_markdown(:pyplot) # generate_markdown(:pyplot)
generate_markdown(:immerse) generate_markdown(:immerse)

View File

@ -33,7 +33,7 @@ plot([sin,cos],0,4π)
Or make a parametric plot with plot(fx, fy, umin, umax). Or make a parametric plot with plot(fx, fy, umin, umax).
```julia ```julia
plot(sin,(x->begin # /Users/tom/.julia/v0.4/Plots/docs/example_generation.jl, line 33: plot(sin,(x->begin # /home/tom/.julia/v0.4/Plots/docs/example_generation.jl, line 33:
sin(2x) sin(2x)
end),0,2π) end),0,2π)
``` ```

View File

@ -33,7 +33,7 @@ plot([sin,cos],0,4π)
Or make a parametric plot with plot(fx, fy, umin, umax). Or make a parametric plot with plot(fx, fy, umin, umax).
```julia ```julia
plot(sin,(x->begin # /Users/tom/.julia/v0.4/Plots/docs/example_generation.jl, line 33: plot(sin,(x->begin # /home/tom/.julia/v0.4/Plots/docs/example_generation.jl, line 33:
sin(2x) sin(2x)
end),0,2π) end),0,2π)
``` ```

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 84 KiB

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 87 KiB

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 65 KiB

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 60 KiB

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 39 KiB

View File

@ -31,45 +31,18 @@ function createGadflyPlotObject(d::Dict)
end end
function getGeomsFromLineType(linetype::Symbol)
linetype == :line && return [Gadfly.Geom.path]
linetype == :dots && return [Gadfly.Geom.point]
linetype == :bar && return [Gadfly.Geom.bar]
linetype == :step && return [Gadfly.Geom.step]
# linetype == :hist && return [Gadfly.Geom.histogram(bincount=nbins)]
# linetype == :none && return [Gadfly.Geom.point] # change this? are we usually pairing no line with scatterplots?
linetype == :none && return []
linetype == :sticks && return [Gadfly.Geom.bar]
error("linetype $linetype not currently supported with Gadfly")
end
# function getGeoms(linetype::Symbol, marker::Symbol, markercolor::Colorant, nbins::Int) # function getGeoms(linetype::Symbol, marker::Symbol, markercolor::Colorant, nbins::Int)
function getLineGeoms(d::Dict) function getLineGeoms(d::Dict)
lt = d[:linetype] lt = d[:linetype]
lt in (:heatmap,:hexbin) && return [Gadfly.Geom.hexbin(xbincount = d[:nbins], ybincount = d[:nbins])] lt in (:heatmap,:hexbin) && return [Gadfly.Geom.hexbin(xbincount = d[:nbins], ybincount = d[:nbins])]
lt == :hist && return [Gadfly.Geom.histogram(bincount = d[:nbins])] lt == :hist && return [Gadfly.Geom.histogram(bincount = d[:nbins])]
lt == :none && return [] lt == :none && return [Gadfly.Geom.path]
lt == :line && return [Gadfly.Geom.path] lt == :line && return [Gadfly.Geom.path]
lt == :dots && return [Gadfly.Geom.point] # lt == :dots && return [Gadfly.Geom.point]
lt == :bar && return [Gadfly.Geom.bar] lt == :bar && return [Gadfly.Geom.bar]
lt == :step && return [Gadfly.Geom.step] lt == :step && return [Gadfly.Geom.step]
lt == :sticks && return [Gadfly.Geom.bar] lt == :sticks && return [Gadfly.Geom.bar]
error("linetype $lt not currently supported with Gadfly") error("linetype $lt not currently supported with Gadfly")
# else
# geoms = []
# # for other linetypes, get the correct Geom
# append!(geoms, getGeomFromLineType(lt, nbins))
# # # for any marker, add Geom.point
# # if marker != :none
# # # push!(geoms, Gadfly.Geom.default_point_size)
# # push!(geoms, getGadflyMarker(marker, markercolor))
# # end
# end
# geoms
end end
@ -79,22 +52,33 @@ function getMarkerGeomsAndGuides(d::Dict)
marker = d[:marker] marker = d[:marker]
if marker == :none if marker == :none
return [],[] return [],[]
# special handling for other marker shapes... gotta create Compose contexts and map them to series points using Guide.Annotation
elseif marker == :rect elseif marker == :rect
# get the width/height of the square (both are sz)
sz = d[:markersize] * Gadfly.px sz = d[:markersize] * Gadfly.px
# primitive = Gadfly.Compose.PolygonPrimitive() halfsz = sz/2
# remap x/y to the corner position of the squares
xs = map(z -> Gadfly.Compose.Measure(;cx=z) - halfsz, float(d[:x]))
ys = map(z -> Gadfly.Compose.Measure(;cy=z) + halfsz, float(d[:y]))
# xs = [xi * Gadfly.mm - sz/2 for xi in d[:x]] # return an Annotation which will add those shapes to each point in the series
# ys = [yi * Gadfly.mm - sz/2 for yi in d[:y]]
xs = collect(d[:x])
ys = collect(d[:y])
# xs = collect(d[:x]) - sz/2
# ys = collect(d[:y]) - sz/2
# w = [d[:markersize] * Gadfly.px]
# h = [d[:markersize] * Gadfly.px]
return [], [Gadfly.Guide.annotation(Gadfly.compose(Gadfly.context(), Gadfly.rectangle(xs,ys,[sz],[sz]), Gadfly.fill(d[:markercolor]), Gadfly.stroke(nothing)))] return [], [Gadfly.Guide.annotation(Gadfly.compose(Gadfly.context(), Gadfly.rectangle(xs,ys,[sz],[sz]), Gadfly.fill(d[:markercolor]), Gadfly.stroke(nothing)))]
else
# make circles
sz = 0.5 * d[:markersize] * Gadfly.px
xs = collect(float(d[:x]))
ys = collect(float(d[:y]))
# return an Annotation which will add those shapes to each point in the series
return [], [Gadfly.Guide.annotation(Gadfly.compose(Gadfly.context(), Gadfly.circle(xs,ys,[sz]), Gadfly.fill(d[:markercolor]), Gadfly.stroke(nothing)))]
end end
[Gadfly.Geom.point], []
# otherwise just return a Geom.point
# [Gadfly.Geom.point], []
end end
@ -114,26 +98,27 @@ function addGadflySeries!(gplt, d::Dict)
push!(gfargs, Gadfly.Geom.smooth(method=:lm)) push!(gfargs, Gadfly.Geom.smooth(method=:lm))
end end
# add to the legend
if length(gplt.guides) > 0 && isa(gplt.guides[1], Gadfly.Guide.ManualColorKey)
push!(gplt.guides[1].labels, d[:label])
push!(gplt.guides[1].colors, d[:marker] == :none ? d[:color] : d[:markercolor])
end
# if we haven't added any geoms, we're probably just going to use annotations?
isempty(gfargs) && return # # if we haven't added any geoms, we're probably just going to use annotations?
# isempty(gfargs) && return
# set theme: color, line width, and point size # set theme: color, line width, and point size
line_width = d[:width] * (d[:linetype] == :none ? 0 : 1) * Gadfly.px # 0 width when we don't show a line
theme = Gadfly.Theme(default_color = d[:color], theme = Gadfly.Theme(default_color = d[:color],
line_width = d[:width] * Gadfly.px, line_width = line_width,
default_point_size = d[:markersize] * Gadfly.px) default_point_size = 0.5 * d[:markersize] * Gadfly.px)
push!(gfargs, theme) push!(gfargs, theme)
# for histograms, set x=y # for histograms, set x=y
x = d[d[:linetype] == :hist ? :y : :x] x = d[d[:linetype] == :hist ? :y : :x]
# add to the legend
if length(gplt.guides) > 0 && isa(gplt.guides[1], Gadfly.Guide.ManualColorKey)
push!(gplt.guides[1].labels, d[:label])
push!(gplt.guides[1].colors, d[:color])
end
if d[:axis] != :left if d[:axis] != :left
warn("Gadly only supports one y axis") warn("Gadly only supports one y axis")
end end
@ -162,46 +147,6 @@ function plot!(::GadflyPackage, plt::Plot; kw...)
plt plt
end end
# # plot one data series
# function plot!(::GadflyPackage, plt::Plot; kw...)
# d = Dict(kw)
# gfargs = []
# # add the Geoms
# append!(gfargs, getGeoms(d[:linetype], d[:marker], d[:nbins]))
# # set color, line width, and point size
# theme = Gadfly.Theme(default_color = d[:color],
# line_width = d[:width] * Gadfly.px,
# default_point_size = d[:markersize] * Gadfly.px)
# push!(gfargs, theme)
# # add a regression line?
# if d[:reg]
# push!(gfargs, Gadfly.Geom.smooth(method=:lm))
# end
# # for histograms, set x=y
# x = d[d[:linetype] == :hist ? :y : :x]
# # add to the legend
# if length(plt.o.guides) > 0 && isa(plt.o.guides[1], Gadfly.Guide.ManualColorKey)
# push!(plt.o.guides[1].labels, d[:label])
# push!(plt.o.guides[1].colors, d[:color])
# end
# if d[:axis] != :left
# warn("Gadly only supports one y axis")
# end
# # save the kw args
# push!(plt.seriesargs, d)
# # add the layer to the Gadfly.Plot
# prepend!(plt.o.layers, Gadfly.layer(unique(gfargs)..., d[:args]...; x = x, y = d[:y], d[:kwargs]...))
# plt
# end
function Base.display(::GadflyPackage, plt::Plot) function Base.display(::GadflyPackage, plt::Plot)
display(plt.o) display(plt.o)
@ -235,21 +180,10 @@ end
# create the underlying object (each backend will do this differently) # create the underlying object (each backend will do this differently)
function buildSubplotObject!(::GadflyPackage, subplt::Subplot) function buildSubplotObject!(::GadflyPackage, subplt::Subplot)
# i = 0
# rows = []
# for rowcnt in subplt.layout.rowcounts
# push!(rows, Gadfly.hstack([getGadflyContext(plt.plotter, plt) for plt in subplt.plts[(1:rowcnt) + i]]...))
# i += rowcnt
# end
# subplt.o = Gadfly.vstack(rows...)
# subplt.o = buildGadflySubplotContext(subplt)
subplt.o = nothing subplt.o = nothing
end end
function Base.display(::GadflyPackage, subplt::Subplot) function Base.display(::GadflyPackage, subplt::Subplot)
# getGadflyContext!(subplt.plotter, subplt)
# display(subplt.o)
println("HERE"); sleep(2)
display(buildGadflySubplotContext(subplt)) display(buildGadflySubplotContext(subplt))
end end

View File

@ -7,7 +7,7 @@ immerse!() = plotter!(:immerse)
function createImmerseFigure(d::Dict) function createImmerseFigure(d::Dict)
println("Creating immerse figure: ", d) # println("Creating immerse figure: ", d)
w,h = d[:size] w,h = d[:size]
figidx = Immerse.figure(; name = d[:windowtitle], width = w, height = h) figidx = Immerse.figure(; name = d[:windowtitle], width = w, height = h)
Immerse.Figure(figidx) Immerse.Figure(figidx)
@ -36,7 +36,6 @@ function plot!(::ImmersePackage, plt::Plot; kw...)
end end
function Base.display(::ImmersePackage, plt::Plot) function Base.display(::ImmersePackage, plt::Plot)
println("disp1")
fig, gplt = plt.o fig, gplt = plt.o
if fig == nothing if fig == nothing
@ -65,6 +64,10 @@ end
# ------------------------------- # -------------------------------
# function buildSubplotObject!(::ImmersePackage, subplt::Subplot)
# end
# create the underlying object # create the underlying object
function buildSubplotObject!(::ImmersePackage, subplt::Subplot) function buildSubplotObject!(::ImmersePackage, subplt::Subplot)
subplt.o = (nothing, nothing) subplt.o = (nothing, nothing)
@ -72,7 +75,6 @@ end
function Base.display(::ImmersePackage, subplt::Subplot) function Base.display(::ImmersePackage, subplt::Subplot)
println("disp2")
fig, gctx = subplt.o fig, gctx = subplt.o
if fig == nothing if fig == nothing