diff --git a/README.md b/README.md index 483afb85..8c26e0bc 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Do a plot in Gadfly, then save a png: ``` plotter!(:gadfly) # switches the backend to Gadfly plot(rand(10,2); marker = :rect) -savepng(ans, Plots.IMG_DIR * "gadfly1.png", 6 * Gadfly.inch, 4 * Gadfly.inch) +savepng(ans, Plots.IMG_DIR * "gadfly1.png") ``` which saves: diff --git a/docs/example_generation.jl b/docs/example_generation.jl new file mode 100644 index 00000000..360f790f --- /dev/null +++ b/docs/example_generation.jl @@ -0,0 +1,46 @@ + +module PlotExamples + +using Plots + +const DOCDIR = Pkg.dir("Plots") * "/docs" + +doc""" +Holds all data needed for a documentation example... header, description, and plotting expression (Expr) +""" +type PlotExample + header::String + desc::String + expr::Expr +end + +examples = PlotExample[ + PlotExample("Lines", + "A simple line plot of the 3 columns.", + :(plot(rand(100,3)))), + PlotExample("Functions", + "Plot multiple functions", + :(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))), + PlotExample("Vectors", + "Plot multiple series with different numbers of points.", + :(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, markercolors=[:red,:blue]))), +] + + +function generate_markdown(modname) + plotter!(modname) + +end + +# run it! +map(generate_markdown, (:qwt, :gadfly)) + + +end # module + diff --git a/img/gadfly1.png b/img/gadfly1.png index ce1560ac..1c9caaa8 100644 Binary files a/img/gadfly1.png and b/img/gadfly1.png differ diff --git a/src/Plots.jl b/src/Plots.jl index 316d3813..4d07c571 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -102,8 +102,10 @@ heatmap!(args...; kw...) = plot!(args...; kw..., linetype = :heatmap) # subplot(args...; kw...) = subplot(plotter(), args...; kw...) -savepng(args...; kw...) = savepng(plotter(), args...; kw...) +# savepng(args...; kw...) = savepng(plotter(), args...; kw...) +savepng(args...; kw...) = savepng(currentPlot(), args...; kw...) +savepng(plt::Plot, args...; kw...) = savepng(plt.plotter, plt, args...; kw...) # --------------------------------------------------------- diff --git a/src/gadfly.jl b/src/gadfly.jl index 2a9836f1..b3dbdabe 100644 --- a/src/gadfly.jl +++ b/src/gadfly.jl @@ -86,6 +86,10 @@ function Base.display(::GadflyPackage, plt::Plot) end -savepng(::GadflyPackage, plt::Plot, fn::String, args...) = Gadfly.draw(Gadfly.PNG(fn, args...), plt.o) +function savepng(::GadflyPackage, plt::Plot, fn::String; + w = 6 * Gadfly.inch, + h = 4 * Gadfly.inch) + Gadfly.draw(Gadfly.PNG(fn, w, h), plt.o) +end