savepng fix and started example_generation
This commit is contained in:
parent
dded3a5c82
commit
378c85675b
@ -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:
|
||||
|
||||
46
docs/example_generation.jl
Normal file
46
docs/example_generation.jl
Normal file
@ -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
|
||||
|
||||
BIN
img/gadfly1.png
BIN
img/gadfly1.png
Binary file not shown.
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 35 KiB |
@ -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...)
|
||||
|
||||
|
||||
# ---------------------------------------------------------
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user