diff --git a/docs/example_generation.jl b/docs/example_generation.jl index 1bb9fc0f..75157637 100644 --- a/docs/example_generation.jl +++ b/docs/example_generation.jl @@ -2,6 +2,7 @@ module PlotExamples using Plots +using Colors const DOCDIR = Pkg.dir("Plots") * "/docs" const IMGDIR = Pkg.dir("Plots") * "/img" @@ -26,7 +27,7 @@ const examples = PlotExample[ :(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=:red))), + :(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))), @@ -40,7 +41,7 @@ function generate_markdown(pkgname::Symbol) # set up the plotter, and don't show the plots by default plotter!(pkgname) - + plotDefault!(:show, false) # open the markdown file md = open("$DOCDIR/$(pkgname)_examples.md", "w") @@ -56,10 +57,11 @@ function generate_markdown(pkgname::Symbol) imgname = "$(pkgname)_example_$i.png" savepng("$IMGDIR/$imgname") + # 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, "![](../$imgname)\n\n") + write(md, "![](../img/$imgname)\n\n") catch ex # TODO: put error info into markdown? diff --git a/docs/gadfly_examples.md b/docs/gadfly_examples.md index 1656fb14..b8168d3d 100644 --- a/docs/gadfly_examples.md +++ b/docs/gadfly_examples.md @@ -6,17 +6,27 @@ A simple line plot of the 3 columns. plot(rand(100,3)) ``` -![](../gadfly_example_1.png) +![](../img/gadfly_example_1.png) + +### Functions + +Plot multiple functions + +```julia +plot(0:0.01:4π,[sin,cos]) +``` + +![](../img/gadfly_example_2.png) ### Global Change the guides/background without a separate call. ```julia -plot(rand(10); title="TITLE",xlabel="XLABEL",ylabel="YLABEL",background_color=:red) +plot(rand(10); title="TITLE",xlabel="XLABEL",ylabel="YLABEL",background_color=RGB(0.5,0.5,0.5)) ``` -![](../gadfly_example_3.png) +![](../img/gadfly_example_3.png) ### Vectors @@ -26,7 +36,7 @@ Plot multiple series with different numbers of points. plot(Vector[rand(10),rand(20)]; marker=:ellipse,markersize=8) ``` -![](../gadfly_example_4.png) +![](../img/gadfly_example_4.png) ### Vectors w/ pluralized args @@ -36,5 +46,5 @@ Mix arguments that apply to all series with arguments unique to each series. plot(Vector[rand(10),rand(20)]; marker=:ellipse,markersize=8,markercolors=[:red,:blue]) ``` -![](../gadfly_example_5.png) +![](../img/gadfly_example_5.png) diff --git a/docs/qwt_examples.md b/docs/qwt_examples.md index ec24bea2..2372bfa3 100644 --- a/docs/qwt_examples.md +++ b/docs/qwt_examples.md @@ -6,17 +6,27 @@ A simple line plot of the 3 columns. plot(rand(100,3)) ``` -![](../qwt_example_1.png) +![](../img/qwt_example_1.png) + +### Functions + +Plot multiple functions + +```julia +plot(0:0.01:4π,[sin,cos]) +``` + +![](../img/qwt_example_2.png) ### Global Change the guides/background without a separate call. ```julia -plot(rand(10); title="TITLE",xlabel="XLABEL",ylabel="YLABEL",background_color=:red) +plot(rand(10); title="TITLE",xlabel="XLABEL",ylabel="YLABEL",background_color=RGB(0.5,0.5,0.5)) ``` -![](../qwt_example_3.png) +![](../img/qwt_example_3.png) ### Vectors @@ -26,7 +36,7 @@ Plot multiple series with different numbers of points. plot(Vector[rand(10),rand(20)]; marker=:ellipse,markersize=8) ``` -![](../qwt_example_4.png) +![](../img/qwt_example_4.png) ### Vectors w/ pluralized args @@ -36,5 +46,5 @@ Mix arguments that apply to all series with arguments unique to each series. plot(Vector[rand(10),rand(20)]; marker=:ellipse,markersize=8,markercolors=[:red,:blue]) ``` -![](../qwt_example_5.png) +![](../img/qwt_example_5.png) diff --git a/img/gadfly_example_1.png b/img/gadfly_example_1.png index 0e78cf2d..0f15cea1 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 new file mode 100644 index 00000000..db8d3723 Binary files /dev/null and b/img/gadfly_example_2.png differ diff --git a/img/gadfly_example_3.png b/img/gadfly_example_3.png index dbb41fd2..e0e5216c 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 e11b7a91..3aad05b9 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 6ec63145..8b810f04 100644 Binary files a/img/gadfly_example_5.png and b/img/gadfly_example_5.png differ diff --git a/img/qwt_example_1.png b/img/qwt_example_1.png index 8a19bc15..c71f3b8d 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 new file mode 100644 index 00000000..910b8847 Binary files /dev/null and b/img/qwt_example_2.png differ diff --git a/img/qwt_example_3.png b/img/qwt_example_3.png index 4691cc91..5975dd46 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 f337eedf..41dd7207 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 68d3e077..82565340 100644 Binary files a/img/qwt_example_5.png and b/img/qwt_example_5.png differ diff --git a/src/args.jl b/src/args.jl index b03c12be..cd569e3d 100644 --- a/src/args.jl +++ b/src/args.jl @@ -39,6 +39,7 @@ PLOT_DEFAULTS[:legend] = true # PLOT_DEFAULTS[:background_color] = nothing PLOT_DEFAULTS[:xticks] = true PLOT_DEFAULTS[:yticks] = true +PLOT_DEFAULTS[:size] = (600,400) # TODO: x/y scales diff --git a/src/plot.jl b/src/plot.jl index 448b2702..4eb1cc96 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -141,6 +141,7 @@ function plot!(pkg::PlottingPackage, plt::Plot, x::AMat, y::AMat; kw...) end function plot!(pkg::PlottingPackage, plt::Plot, x::AVec, f::Function; kw...) # one line, y = f(x) + plt.n += 1 plot!(pkg, plt; x = x, y = map(f,x), getPlotKeywordArgs(kw, 1, plt)...) end @@ -153,13 +154,13 @@ function plot!(pkg::PlottingPackage, plt::Plot, x::AMat, f::Function; kw...) plt end -function plot!(pkg::PlottingPackage, plt::Plot, x::AVec, fs::AVec{Function}; kw...) # multiple lines, yᵢⱼ = fⱼ(xᵢ) - for i in 1:length(fs) - plt.n += 1 - plot!(pkg, plt; x = x, y = map(fs[i], x), getPlotKeywordArgs(kw, i, plt)...) - end - plt -end +# function plot!(pkg::PlottingPackage, plt::Plot, x::AVec, fs::AVec{Function}; kw...) # multiple lines, yᵢⱼ = fⱼ(xᵢ) +# for i in 1:length(fs) +# plt.n += 1 +# plot!(pkg, plt; x = x, y = map(fs[i], x), getPlotKeywordArgs(kw, i, plt)...) +# end +# plt +# end function plot!(pkg::PlottingPackage, plt::Plot, y::AVec; kw...) # multiple lines, each with x = 1:length(y[i]) for i in 1:length(y) @@ -171,9 +172,14 @@ end function plot!{T<:Real}(pkg::PlottingPackage, plt::Plot, x::AVec{T}, y::AVec; kw...) # multiple lines, will assert length(x) == length(y[i]) for i in 1:length(y) - @assert length(x) == length(y[i]) - plt.n += 1 - plot!(pkg, plt; x = x, y = y[i], getPlotKeywordArgs(kw, i, plt)...) + if typeof(y[i]) <: AbstractVector + @assert length(x) == length(y[i]) + plt.n += 1 + plot!(pkg, plt; x = x, y = y[i], getPlotKeywordArgs(kw, i, plt)...) + elseif typeof(y[i]) == Function + plt.n += 1 + plot!(pkg, plt; x = x, y = map(y[i], x), getPlotKeywordArgs(kw, 1, plt)...) + end end plt end