working on gadfly markers

This commit is contained in:
Thomas Breloff 2015-09-14 17:27:37 -04:00
parent c4b04e2327
commit 264e8c735e
56 changed files with 87 additions and 60 deletions

View File

@ -90,7 +90,7 @@ function generate_markdown(pkgname::Symbol)
# set up the plotter, and don't show the plots by default # set up the plotter, and don't show the plots by default
plotter!(pkgname) plotter!(pkgname)
plotDefault!(:show, false) # plotDefault!(:show, false)
# mkdir if necessary # mkdir if necessary
try try
@ -131,8 +131,8 @@ 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π)
``` ```
@ -72,6 +72,16 @@ plot(Vector[rand(10),rand(20)]; marker=:ellipse,markersize=8,colors=[:red,:blue]
![](../img/gadfly/gadfly_example_7.png) ![](../img/gadfly/gadfly_example_7.png)
### Build plot in pieces
Start with a base plot...
```julia
plot(rand(100) / 3; reg=true,fillto=0)
```
![](../img/gadfly/gadfly_example_8.png)
### ###
and add to it later. and add to it later.

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: 81 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 76 KiB

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 53 KiB

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 84 KiB

After

Width:  |  Height:  |  Size: 57 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: 55 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 0 B

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 95 KiB

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 21 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: 32 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 81 KiB

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 32 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: 32 KiB

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.3 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.9 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.3 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.3 KiB

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 28 KiB

View File

@ -41,7 +41,7 @@ PLOT_DEFAULTS[:xticks] = true
PLOT_DEFAULTS[:yticks] = true PLOT_DEFAULTS[:yticks] = true
PLOT_DEFAULTS[:size] = (600,400) PLOT_DEFAULTS[:size] = (600,400)
PLOT_DEFAULTS[:windowtitle] = "Plots.jl" PLOT_DEFAULTS[:windowtitle] = "Plots.jl"
PLOT_DEFAULTS[:show] = true # PLOT_DEFAULTS[:show] = true
PLOT_DEFAULTS[:args] = [] # additional args to pass to the backend PLOT_DEFAULTS[:args] = [] # additional args to pass to the backend
PLOT_DEFAULTS[:kwargs] = [] # additional keyword args to pass to the backend PLOT_DEFAULTS[:kwargs] = [] # additional keyword args to pass to the backend

View File

@ -6,31 +6,6 @@ immutable GadflyPackage <: PlottingPackage end
gadfly!() = plotter!(:gadfly) gadfly!() = plotter!(:gadfly)
# # 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])]
# # add the legend?
# if d[:legend]
# unshift!(plt.guides, Gadfly.Guide.manual_color_key("", AbstractString[], Color[]))
# end
# plt.theme = Gadfly.Theme(background_color = (haskey(d, :background_color) ? d[:background_color] : colorant"white"))
# Plot(plt, pkg, 0, d, Dict[])
# end
function createGadflyPlotObject(d::Dict) function createGadflyPlotObject(d::Dict)
@eval import DataFrames @eval import DataFrames
@ -56,35 +31,67 @@ function createGadflyPlotObject(d::Dict)
end end
function getGeomFromLineType(linetype::Symbol, nbins::Int) function getGeomsFromLineType(linetype::Symbol)
linetype == :line && return Gadfly.Geom.line linetype == :line && return [Gadfly.Geom.path]
linetype == :dots && return Gadfly.Geom.point linetype == :dots && return [Gadfly.Geom.point]
linetype == :bar && return Gadfly.Geom.bar linetype == :bar && return [Gadfly.Geom.bar]
linetype == :step && return Gadfly.Geom.step linetype == :step && return [Gadfly.Geom.step]
linetype == :hist && return Gadfly.Geom.histogram(bincount=nbins) # 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 [Gadfly.Geom.point] # change this? are we usually pairing no line with scatterplots?
linetype == :sticks && return Gadfly.Geom.bar linetype == :none && return []
linetype == :sticks && return [Gadfly.Geom.bar]
error("linetype $linetype not currently supported with Gadfly") error("linetype $linetype not currently supported with Gadfly")
end end
function getGeoms(linetype::Symbol, marker::Symbol, nbins::Int) # function getGeoms(linetype::Symbol, marker::Symbol, markercolor::Colorant, nbins::Int)
geoms = [] function getLineGeoms(d::Dict)
lt = d[:linetype]
lt in (:heatmap,:hexbin) && return [Gadfly.Geom.hexbin(xbincount = d[:nbins], ybincount = d[:nbins])]
lt == :hist && return [Gadfly.Geom.histogram(bincount = d[:nbins])]
lt == :none && return []
lt == :line && return [Gadfly.Geom.path]
lt == :dots && return [Gadfly.Geom.point]
lt == :bar && return [Gadfly.Geom.bar]
lt == :step && return [Gadfly.Geom.step]
lt == :sticks && return [Gadfly.Geom.bar]
error("linetype $lt not currently supported with Gadfly")
# handle heatmaps (hexbins) specially # else
if linetype in (:heatmap,:hexbin) # geoms = []
push!(geoms, Gadfly.Geom.hexbin(xbincount=nbins, ybincount=nbins))
else
# for other linetypes, get the correct Geom # # for other linetypes, get the correct Geom
push!(geoms, getGeomFromLineType(linetype, nbins)) # append!(geoms, getGeomFromLineType(lt, nbins))
# for any marker, add Geom.point # # # for any marker, add Geom.point
if marker != :none # # if marker != :none
push!(geoms, Gadfly.Geom.point) # # # push!(geoms, Gadfly.Geom.default_point_size)
end # # push!(geoms, getGadflyMarker(marker, markercolor))
# # end
# end
# geoms
end
# serious hack (I think?) to draw my own shapes as annotations... will it work? who knows...
function getMarkerGeomsAndGuides(d::Dict)
marker = d[:marker]
if marker == :none
return [],[]
elseif marker == :rect
sz = d[:markersize] * Gadfly.px
# primitive = Gadfly.Compose.PolygonPrimitive()
xs = [xi * Gadfly.mm - sz/2 for xi in d[:x]]
ys = [yi * Gadfly.mm - sz/2 for yi in 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)))]
end end
[Gadfly.Geom.point], []
geoms
end end
@ -92,19 +99,29 @@ function addGadflySeries!(gplt, d::Dict)
gfargs = [] gfargs = []
# add the Geoms # add the Geoms
append!(gfargs, getGeoms(d[:linetype], d[:marker], d[:nbins])) append!(gfargs, getLineGeoms(d)) #[:linetype], d[:marker], d[:markercolor], d[:nbins]))
# set color, line width, and point size # handle markers
theme = Gadfly.Theme(default_color = d[:color], geoms, guides = getMarkerGeomsAndGuides(d)
line_width = d[:width] * Gadfly.px, append!(gfargs, geoms)
default_point_size = d[:markersize] * Gadfly.px) append!(gplt.guides, guides)
push!(gfargs, theme)
# add a regression line? # add a regression line?
if d[:reg] if d[:reg]
push!(gfargs, Gadfly.Geom.smooth(method=:lm)) push!(gfargs, Gadfly.Geom.smooth(method=:lm))
end end
# 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
theme = Gadfly.Theme(default_color = d[:color],
line_width = d[:width] * Gadfly.px,
default_point_size = d[:markersize] * Gadfly.px)
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]