diff --git a/docs/example_generation.jl b/docs/example_generation.jl index 97029227..0c11090e 100644 --- a/docs/example_generation.jl +++ b/docs/example_generation.jl @@ -132,7 +132,7 @@ end # run it! # note: generate separately so it's easy to comment out # generate_markdown(:qwt) -# generate_markdown(:gadfly) +generate_markdown(:gadfly) # @osx_only generate_markdown(:unicodeplots) # generate_markdown(:pyplot) generate_markdown(:immerse) diff --git a/docs/gadfly_examples.md b/docs/gadfly_examples.md index 9cb046ac..6dd8f49d 100644 --- a/docs/gadfly_examples.md +++ b/docs/gadfly_examples.md @@ -33,7 +33,7 @@ plot([sin,cos],0,4π) Or make a parametric plot with plot(fx, fy, umin, umax). ```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) end),0,2π) ``` diff --git a/docs/immerse_examples.md b/docs/immerse_examples.md index 6f73e2f8..fd544489 100644 --- a/docs/immerse_examples.md +++ b/docs/immerse_examples.md @@ -33,7 +33,7 @@ plot([sin,cos],0,4π) Or make a parametric plot with plot(fx, fy, umin, umax). ```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) end),0,2π) ``` diff --git a/img/gadfly/gadfly_example_1.png b/img/gadfly/gadfly_example_1.png index b5f7cfb0..5c291d92 100644 Binary files a/img/gadfly/gadfly_example_1.png and b/img/gadfly/gadfly_example_1.png differ diff --git a/img/gadfly/gadfly_example_10.png b/img/gadfly/gadfly_example_10.png index 560dcdbd..a6c8c54e 100644 Binary files a/img/gadfly/gadfly_example_10.png and b/img/gadfly/gadfly_example_10.png differ diff --git a/img/gadfly/gadfly_example_11.png b/img/gadfly/gadfly_example_11.png index c1dd5d6d..a4b43b2a 100644 Binary files a/img/gadfly/gadfly_example_11.png and b/img/gadfly/gadfly_example_11.png differ diff --git a/img/gadfly/gadfly_example_12.png b/img/gadfly/gadfly_example_12.png index 81d374c9..334c8ff6 100644 Binary files a/img/gadfly/gadfly_example_12.png and b/img/gadfly/gadfly_example_12.png differ diff --git a/img/gadfly/gadfly_example_13.png b/img/gadfly/gadfly_example_13.png index 19088f2e..dd76c86f 100644 Binary files a/img/gadfly/gadfly_example_13.png and b/img/gadfly/gadfly_example_13.png differ diff --git a/img/gadfly/gadfly_example_14.png b/img/gadfly/gadfly_example_14.png index 5303d22c..6115e3e1 100644 Binary files a/img/gadfly/gadfly_example_14.png and b/img/gadfly/gadfly_example_14.png differ diff --git a/img/gadfly/gadfly_example_15.png b/img/gadfly/gadfly_example_15.png index 7c0759aa..4c92cdaf 100644 Binary files a/img/gadfly/gadfly_example_15.png and b/img/gadfly/gadfly_example_15.png differ diff --git a/img/gadfly/gadfly_example_16.png b/img/gadfly/gadfly_example_16.png index 72de083f..7bf8bab3 100644 Binary files a/img/gadfly/gadfly_example_16.png and b/img/gadfly/gadfly_example_16.png differ diff --git a/img/gadfly/gadfly_example_17.png b/img/gadfly/gadfly_example_17.png index 4f39d156..3e45d0fe 100644 Binary files a/img/gadfly/gadfly_example_17.png and b/img/gadfly/gadfly_example_17.png differ diff --git a/img/gadfly/gadfly_example_18.png b/img/gadfly/gadfly_example_18.png index 8425bc6a..7c4995b5 100644 Binary files a/img/gadfly/gadfly_example_18.png and b/img/gadfly/gadfly_example_18.png differ diff --git a/img/gadfly/gadfly_example_2.png b/img/gadfly/gadfly_example_2.png index efa14361..28515e94 100644 Binary files a/img/gadfly/gadfly_example_2.png and b/img/gadfly/gadfly_example_2.png differ diff --git a/img/gadfly/gadfly_example_3.png b/img/gadfly/gadfly_example_3.png index 6c59403e..d137d591 100644 Binary files a/img/gadfly/gadfly_example_3.png and b/img/gadfly/gadfly_example_3.png differ diff --git a/img/gadfly/gadfly_example_4.png b/img/gadfly/gadfly_example_4.png index 5ee60f33..c995d521 100644 Binary files a/img/gadfly/gadfly_example_4.png and b/img/gadfly/gadfly_example_4.png differ diff --git a/img/gadfly/gadfly_example_5.png b/img/gadfly/gadfly_example_5.png index 30198f22..787ef387 100644 Binary files a/img/gadfly/gadfly_example_5.png and b/img/gadfly/gadfly_example_5.png differ diff --git a/img/gadfly/gadfly_example_6.png b/img/gadfly/gadfly_example_6.png index 7b429985..79e552d5 100644 Binary files a/img/gadfly/gadfly_example_6.png and b/img/gadfly/gadfly_example_6.png differ diff --git a/img/gadfly/gadfly_example_7.png b/img/gadfly/gadfly_example_7.png index c4840acf..439e0451 100644 Binary files a/img/gadfly/gadfly_example_7.png and b/img/gadfly/gadfly_example_7.png differ diff --git a/img/gadfly/gadfly_example_8.png b/img/gadfly/gadfly_example_8.png index f4f1f7fd..b8d0299f 100644 Binary files a/img/gadfly/gadfly_example_8.png and b/img/gadfly/gadfly_example_8.png differ diff --git a/img/gadfly/gadfly_example_9.png b/img/gadfly/gadfly_example_9.png index 5cfe44d3..a59e17af 100644 Binary files a/img/gadfly/gadfly_example_9.png and b/img/gadfly/gadfly_example_9.png differ diff --git a/img/immerse/immerse_example_1.png b/img/immerse/immerse_example_1.png index ac1be05d..953889e4 100644 Binary files a/img/immerse/immerse_example_1.png and b/img/immerse/immerse_example_1.png differ diff --git a/img/immerse/immerse_example_10.png b/img/immerse/immerse_example_10.png index 3d40d5f8..797183de 100644 Binary files a/img/immerse/immerse_example_10.png and b/img/immerse/immerse_example_10.png differ diff --git a/img/immerse/immerse_example_11.png b/img/immerse/immerse_example_11.png index a73361c8..8909cc91 100644 Binary files a/img/immerse/immerse_example_11.png and b/img/immerse/immerse_example_11.png differ diff --git a/img/immerse/immerse_example_12.png b/img/immerse/immerse_example_12.png index 67ce63ef..70d1c421 100644 Binary files a/img/immerse/immerse_example_12.png and b/img/immerse/immerse_example_12.png differ diff --git a/img/immerse/immerse_example_13.png b/img/immerse/immerse_example_13.png index 62d5505d..dd76c86f 100644 Binary files a/img/immerse/immerse_example_13.png and b/img/immerse/immerse_example_13.png differ diff --git a/img/immerse/immerse_example_14.png b/img/immerse/immerse_example_14.png index 30be7389..73e5747a 100644 Binary files a/img/immerse/immerse_example_14.png and b/img/immerse/immerse_example_14.png differ diff --git a/img/immerse/immerse_example_15.png b/img/immerse/immerse_example_15.png index 3abf4672..a2d3ec2e 100644 Binary files a/img/immerse/immerse_example_15.png and b/img/immerse/immerse_example_15.png differ diff --git a/img/immerse/immerse_example_16.png b/img/immerse/immerse_example_16.png index ba53e413..5bbccbba 100644 Binary files a/img/immerse/immerse_example_16.png and b/img/immerse/immerse_example_16.png differ diff --git a/img/immerse/immerse_example_17.png b/img/immerse/immerse_example_17.png index c9106c14..09381e84 100644 Binary files a/img/immerse/immerse_example_17.png and b/img/immerse/immerse_example_17.png differ diff --git a/img/immerse/immerse_example_18.png b/img/immerse/immerse_example_18.png index 6e18c7d9..053fca59 100644 Binary files a/img/immerse/immerse_example_18.png and b/img/immerse/immerse_example_18.png differ diff --git a/img/immerse/immerse_example_2.png b/img/immerse/immerse_example_2.png index efa14361..28515e94 100644 Binary files a/img/immerse/immerse_example_2.png and b/img/immerse/immerse_example_2.png differ diff --git a/img/immerse/immerse_example_3.png b/img/immerse/immerse_example_3.png index 6c59403e..d137d591 100644 Binary files a/img/immerse/immerse_example_3.png and b/img/immerse/immerse_example_3.png differ diff --git a/img/immerse/immerse_example_4.png b/img/immerse/immerse_example_4.png index 5ee60f33..c995d521 100644 Binary files a/img/immerse/immerse_example_4.png and b/img/immerse/immerse_example_4.png differ diff --git a/img/immerse/immerse_example_5.png b/img/immerse/immerse_example_5.png index 100a93be..3175d677 100644 Binary files a/img/immerse/immerse_example_5.png and b/img/immerse/immerse_example_5.png differ diff --git a/img/immerse/immerse_example_6.png b/img/immerse/immerse_example_6.png index 6f5f4d79..03bc7441 100644 Binary files a/img/immerse/immerse_example_6.png and b/img/immerse/immerse_example_6.png differ diff --git a/img/immerse/immerse_example_7.png b/img/immerse/immerse_example_7.png index 3a57d96f..6185d2bb 100644 Binary files a/img/immerse/immerse_example_7.png and b/img/immerse/immerse_example_7.png differ diff --git a/img/immerse/immerse_example_8.png b/img/immerse/immerse_example_8.png index 26eba4ff..2a290eb4 100644 Binary files a/img/immerse/immerse_example_8.png and b/img/immerse/immerse_example_8.png differ diff --git a/img/immerse/immerse_example_9.png b/img/immerse/immerse_example_9.png index 7603f88d..158b2aba 100644 Binary files a/img/immerse/immerse_example_9.png and b/img/immerse/immerse_example_9.png differ diff --git a/src/backends/gadfly.jl b/src/backends/gadfly.jl index 8718a6c2..aa0eba5d 100644 --- a/src/backends/gadfly.jl +++ b/src/backends/gadfly.jl @@ -31,45 +31,18 @@ function createGadflyPlotObject(d::Dict) 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 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 == :none && 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 == :step && return [Gadfly.Geom.step] lt == :sticks && return [Gadfly.Geom.bar] 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 @@ -79,22 +52,33 @@ function getMarkerGeomsAndGuides(d::Dict) marker = d[:marker] if marker == :none return [],[] + + # special handling for other marker shapes... gotta create Compose contexts and map them to series points using Guide.Annotation elseif marker == :rect + # get the width/height of the square (both are sz) 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]] - # 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 an Annotation which will add those shapes to each point in the series 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 - [Gadfly.Geom.point], [] + + # otherwise just return a Geom.point + # [Gadfly.Geom.point], [] end @@ -114,26 +98,27 @@ function addGadflySeries!(gplt, d::Dict) push!(gfargs, Gadfly.Geom.smooth(method=:lm)) 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 + 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], - line_width = d[:width] * Gadfly.px, - default_point_size = d[:markersize] * Gadfly.px) + line_width = line_width, + default_point_size = 0.5 * d[:markersize] * Gadfly.px) push!(gfargs, theme) # for histograms, set x=y 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 warn("Gadly only supports one y axis") end @@ -162,46 +147,6 @@ function plot!(::GadflyPackage, plt::Plot; kw...) plt 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) display(plt.o) @@ -235,21 +180,10 @@ end # create the underlying object (each backend will do this differently) 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 end function Base.display(::GadflyPackage, subplt::Subplot) - # getGadflyContext!(subplt.plotter, subplt) - # display(subplt.o) - println("HERE"); sleep(2) display(buildGadflySubplotContext(subplt)) end diff --git a/src/backends/immerse.jl b/src/backends/immerse.jl index 6be972dc..05979278 100644 --- a/src/backends/immerse.jl +++ b/src/backends/immerse.jl @@ -7,7 +7,7 @@ immerse!() = plotter!(:immerse) function createImmerseFigure(d::Dict) - println("Creating immerse figure: ", d) + # println("Creating immerse figure: ", d) w,h = d[:size] figidx = Immerse.figure(; name = d[:windowtitle], width = w, height = h) Immerse.Figure(figidx) @@ -36,7 +36,6 @@ function plot!(::ImmersePackage, plt::Plot; kw...) end function Base.display(::ImmersePackage, plt::Plot) - println("disp1") fig, gplt = plt.o if fig == nothing @@ -65,6 +64,10 @@ end # ------------------------------- +# function buildSubplotObject!(::ImmersePackage, subplt::Subplot) +# end + + # create the underlying object function buildSubplotObject!(::ImmersePackage, subplt::Subplot) subplt.o = (nothing, nothing) @@ -72,7 +75,6 @@ end function Base.display(::ImmersePackage, subplt::Subplot) - println("disp2") fig, gctx = subplt.o if fig == nothing