diff --git a/README.md b/README.md index 8c26e0bc..01d8cbd9 100644 --- a/README.md +++ b/README.md @@ -107,8 +107,8 @@ Here are some various args to supply, and the implicit mapping (AVec == Abstract Shorthands: ``` - scatter(args...; kw...) = plot(args...; kw..., linetype = :none, marker = :rect) - scatter!(args...; kw...) = plot!(args...; kw..., linetype = :none, marker = :rect) + scatter(args...; kw...) = plot(args...; kw..., linetype = :none, marker = :hexagon) + scatter!(args...; kw...) = plot!(args...; kw..., linetype = :none, marker = :hexagon) bar(args...; kw...) = plot(args...; kw..., linetype = :bar) bar!(args...; kw...) = plot!(args...; kw..., linetype = :bar) histogram(args...; kw...) = plot(args...; kw..., linetype = :hist) diff --git a/docs/example_generation.jl b/docs/example_generation.jl index 372479bd..e24f9767 100644 --- a/docs/example_generation.jl +++ b/docs/example_generation.jl @@ -13,7 +13,7 @@ Holds all data needed for a documentation example... header, description, and pl type PlotExample header::String desc::String - expr::Expr + exprs::Vector{Expr} end @@ -21,19 +21,22 @@ end const examples = PlotExample[ PlotExample("Lines", "A simple line plot of the 3 columns.", - :(plot(rand(100,3)))), + [:(plot(rand(100,3)))]), PlotExample("Functions", "Plot multiple functions", - :(plot(0:0.01:4π, [sin,cos]))), + [:(plot(0:0.01:4π, [sin,cos]))]), PlotExample("Global", "Change the guides/background without a separate call.", - :(plot(rand(10); title="TITLE", xlabel="XLABEL", ylabel="YLABEL", background_color = RGB(0.5,0.5,0.5)))), + [:(plot(rand(10); title="TITLE", xlabel="XLABEL", ylabel="YLABEL", background_color = RGB(0.5,0.5,0.5)))]), PlotExample("Vectors", "Plot multiple series with different numbers of points.", - :(plot(Vector[rand(10), rand(20)]; marker=:ellipse, markersize=8))), + [:(plot(Vector[rand(10), rand(20)]; marker=:ellipse, markersize=8))]), PlotExample("Vectors w/ pluralized args", "Mix arguments that apply to all series with arguments unique to each series.", - :(plot(Vector[rand(10), rand(20)]; marker=:ellipse, markersize=8, colors=[:red,:blue]))), + [:(plot(Vector[rand(10), rand(20)]; marker=:ellipse, markersize=8, colors=[:red,:blue]))]), + PlotExample("Build plot in pieces", + "You can add to a plot at any time.", + [:(plot(rand(100)/3; reg=true, fillto=0)), :(scatter!(rand(100); markersize=6, color=:blue))]), ] @@ -51,7 +54,7 @@ function generate_markdown(pkgname::Symbol) try # run the code - eval(example.expr) + map(eval, example.exprs) # save the png imgname = "$(pkgname)_example_$i.png" @@ -60,7 +63,7 @@ function generate_markdown(pkgname::Symbol) # write out the header, description, code block, and image link write(md, "### $(example.header)\n\n") write(md, "$(example.desc)\n\n") - write(md, "```julia\n$(string(example.expr))\n```\n\n") + write(md, "```julia\n$(join(map(string, example.exprs), "\n"))\n```\n\n") write(md, "![](../img/$imgname)\n\n") catch ex diff --git a/docs/gadfly_examples.md b/docs/gadfly_examples.md index da9a3ddb..e2d1575a 100644 --- a/docs/gadfly_examples.md +++ b/docs/gadfly_examples.md @@ -48,3 +48,14 @@ plot(Vector[rand(10),rand(20)]; marker=:ellipse,markersize=8,colors=[:red,:blue] ![](../img/gadfly_example_5.png) +### Build plot in pieces + +You can add to a plot at any time. + +```julia +plot(rand(100) / 3; reg=true,fillto=0) +scatter!(rand(100); markersize=6,color=:blue) +``` + +![](../img/gadfly_example_6.png) + diff --git a/docs/qwt_examples.md b/docs/qwt_examples.md index 1f135bc9..29458fd9 100644 --- a/docs/qwt_examples.md +++ b/docs/qwt_examples.md @@ -48,3 +48,14 @@ plot(Vector[rand(10),rand(20)]; marker=:ellipse,markersize=8,colors=[:red,:blue] ![](../img/qwt_example_5.png) +### Build plot in pieces + +You can add to a plot at any time. + +```julia +plot(rand(100) / 3; reg=true,fillto=0) +scatter!(rand(100); markersize=6,color=:blue) +``` + +![](../img/qwt_example_6.png) + diff --git a/img/gadfly_example_1.png b/img/gadfly_example_1.png index e6d1baf5..2a6fa158 100644 Binary files a/img/gadfly_example_1.png and b/img/gadfly_example_1.png differ diff --git a/img/gadfly_example_2.png b/img/gadfly_example_2.png index db8d3723..85562f21 100644 Binary files a/img/gadfly_example_2.png and b/img/gadfly_example_2.png differ diff --git a/img/gadfly_example_3.png b/img/gadfly_example_3.png index 0c297919..4366b5f1 100644 Binary files a/img/gadfly_example_3.png and b/img/gadfly_example_3.png differ diff --git a/img/gadfly_example_4.png b/img/gadfly_example_4.png index 00d72bfe..8d802ef9 100644 Binary files a/img/gadfly_example_4.png and b/img/gadfly_example_4.png differ diff --git a/img/gadfly_example_5.png b/img/gadfly_example_5.png index 80d0bcac..ecb3fa7d 100644 Binary files a/img/gadfly_example_5.png and b/img/gadfly_example_5.png differ diff --git a/img/gadfly_example_6.png b/img/gadfly_example_6.png new file mode 100644 index 00000000..3e1271db Binary files /dev/null and b/img/gadfly_example_6.png differ diff --git a/img/qwt_example_1.png b/img/qwt_example_1.png index e3aad7a0..9d5da77a 100644 Binary files a/img/qwt_example_1.png and b/img/qwt_example_1.png differ diff --git a/img/qwt_example_2.png b/img/qwt_example_2.png index 910b8847..399b8809 100644 Binary files a/img/qwt_example_2.png and b/img/qwt_example_2.png differ diff --git a/img/qwt_example_3.png b/img/qwt_example_3.png index 485da862..9cfea17e 100644 Binary files a/img/qwt_example_3.png and b/img/qwt_example_3.png differ diff --git a/img/qwt_example_4.png b/img/qwt_example_4.png index 30cd6e05..d792e301 100644 Binary files a/img/qwt_example_4.png and b/img/qwt_example_4.png differ diff --git a/img/qwt_example_5.png b/img/qwt_example_5.png index 0268664a..c810a75b 100644 Binary files a/img/qwt_example_5.png and b/img/qwt_example_5.png differ diff --git a/img/qwt_example_6.png b/img/qwt_example_6.png new file mode 100644 index 00000000..7f829ee4 Binary files /dev/null and b/img/qwt_example_6.png differ diff --git a/src/Plots.jl b/src/Plots.jl index 7109ff46..efa84f41 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -77,8 +77,8 @@ include("plot.jl") # const LINE_TYPES = (:line, :step, :stepinverted, :sticks, :dots, :none, :heatmap, :hist, :bar) -scatter(args...; kw...) = plot(args...; kw..., linetype = :none, marker = :rect) -scatter!(args...; kw...) = plot!(args...; kw..., linetype = :none, marker = :rect) +scatter(args...; kw...) = plot(args...; kw..., linetype = :none, marker = :hexagon) +scatter!(args...; kw...) = plot!(args...; kw..., linetype = :none, marker = :hexagon) bar(args...; kw...) = plot(args...; kw..., linetype = :bar) bar!(args...; kw...) = plot!(args...; kw..., linetype = :bar) histogram(args...; kw...) = plot(args...; kw..., linetype = :hist) diff --git a/src/args.jl b/src/args.jl index cd569e3d..06592a51 100644 --- a/src/args.jl +++ b/src/args.jl @@ -114,6 +114,10 @@ function getPlotKeywordArgs(kw, i::Int, plt = nothing) mc = outd[:markercolor] mc = (mc == :match ? outd[:color] : getRGBColor(mc, plt.n)) outd[:markercolor] = mc + + # set label + label = outd[:label] + outd[:label] = string(label == "AUTO" ? "y_$i" : label, outd[:axis] == :left ? "" : " (R)") end outd diff --git a/src/gadfly.jl b/src/gadfly.jl index b3dbdabe..c38bdafb 100644 --- a/src/gadfly.jl +++ b/src/gadfly.jl @@ -15,9 +15,17 @@ function plot(pkg::GadflyPackage; kw...) # 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.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")) - # key_position = (d[:legend] ? :bottom : :none)) Plot(plt, pkg, 0) end @@ -76,6 +84,16 @@ function plot!(::GadflyPackage, plt::Plot; kw...) # 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 + # add the layer to the Gadfly.Plot append!(plt.o.layers, Gadfly.layer(unique(gfargs)...; x = x, y = d[:y])) plt diff --git a/src/plotter.jl b/src/plotter.jl index 4672c383..3bf0742e 100644 --- a/src/plotter.jl +++ b/src/plotter.jl @@ -26,7 +26,7 @@ function plotter() if !(currentPackageSymbol in INITIALIZED_PACKAGES) # initialize - print("Initializing package: $CURRENT_PACKAGE... ") + print("[Plots.jl] Initializing package: $CURRENT_PACKAGE... ") if currentPackageSymbol == :qwt @eval import Qwt elseif currentPackageSymbol == :gadfly