gadfly legends; examples
@ -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)
|
||||
|
||||
@ -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, "\n\n")
|
||||
|
||||
catch ex
|
||||
|
||||
@ -48,3 +48,14 @@ plot(Vector[rand(10),rand(20)]; marker=:ellipse,markersize=8,colors=[:red,:blue]
|
||||
|
||||

|
||||
|
||||
### 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)
|
||||
```
|
||||
|
||||

|
||||
|
||||
|
||||
@ -48,3 +48,14 @@ plot(Vector[rand(10),rand(20)]; marker=:ellipse,markersize=8,colors=[:red,:blue]
|
||||
|
||||

|
||||
|
||||
### 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)
|
||||
```
|
||||
|
||||

|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 78 KiB |
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 38 KiB |
BIN
img/gadfly_example_6.png
Normal file
|
After Width: | Height: | Size: 48 KiB |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
BIN
img/qwt_example_6.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||