This commit is contained in:
Thomas Breloff 2015-09-10 15:02:16 -04:00
parent 27b1fea1a3
commit 042ccdc298
15 changed files with 52 additions and 23 deletions

View File

@ -2,6 +2,7 @@
module PlotExamples module PlotExamples
using Plots using Plots
using Colors
const DOCDIR = Pkg.dir("Plots") * "/docs" const DOCDIR = Pkg.dir("Plots") * "/docs"
const IMGDIR = Pkg.dir("Plots") * "/img" const IMGDIR = Pkg.dir("Plots") * "/img"
@ -26,7 +27,7 @@ const examples = PlotExample[
:(plot(0:0.01:4π, [sin,cos]))), :(plot(0:0.01:4π, [sin,cos]))),
PlotExample("Global", PlotExample("Global",
"Change the guides/background without a separate call.", "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", PlotExample("Vectors",
"Plot multiple series with different numbers of points.", "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))),
@ -40,7 +41,7 @@ function generate_markdown(pkgname::Symbol)
# set up the plotter, and don't show the plots by default # set up the plotter, and don't show the plots by default
plotter!(pkgname) plotter!(pkgname)
plotDefault!(:show, false)
# open the markdown file # open the markdown file
md = open("$DOCDIR/$(pkgname)_examples.md", "w") md = open("$DOCDIR/$(pkgname)_examples.md", "w")
@ -56,10 +57,11 @@ function generate_markdown(pkgname::Symbol)
imgname = "$(pkgname)_example_$i.png" imgname = "$(pkgname)_example_$i.png"
savepng("$IMGDIR/$imgname") savepng("$IMGDIR/$imgname")
# write out the header, description, code block, and image link
write(md, "### $(example.header)\n\n") write(md, "### $(example.header)\n\n")
write(md, "$(example.desc)\n\n") write(md, "$(example.desc)\n\n")
write(md, "```julia\n$(string(example.expr))\n```\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 catch ex
# TODO: put error info into markdown? # TODO: put error info into markdown?

View File

@ -6,17 +6,27 @@ A simple line plot of the 3 columns.
plot(rand(100,3)) 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 ### Global
Change the guides/background without a separate call. Change the guides/background without a separate call.
```julia ```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 ### Vectors
@ -26,7 +36,7 @@ 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)
``` ```
![](../gadfly_example_4.png) ![](../img/gadfly_example_4.png)
### Vectors w/ pluralized args ### 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]) plot(Vector[rand(10),rand(20)]; marker=:ellipse,markersize=8,markercolors=[:red,:blue])
``` ```
![](../gadfly_example_5.png) ![](../img/gadfly_example_5.png)

View File

@ -6,17 +6,27 @@ A simple line plot of the 3 columns.
plot(rand(100,3)) 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 ### Global
Change the guides/background without a separate call. Change the guides/background without a separate call.
```julia ```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 ### Vectors
@ -26,7 +36,7 @@ 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)
``` ```
![](../qwt_example_4.png) ![](../img/qwt_example_4.png)
### Vectors w/ pluralized args ### 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]) plot(Vector[rand(10),rand(20)]; marker=:ellipse,markersize=8,markercolors=[:red,:blue])
``` ```
![](../qwt_example_5.png) ![](../img/qwt_example_5.png)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 KiB

After

Width:  |  Height:  |  Size: 79 KiB

BIN
img/gadfly_example_2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 16 KiB

BIN
img/qwt_example_2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -39,6 +39,7 @@ PLOT_DEFAULTS[:legend] = true
# PLOT_DEFAULTS[:background_color] = nothing # PLOT_DEFAULTS[:background_color] = nothing
PLOT_DEFAULTS[:xticks] = true PLOT_DEFAULTS[:xticks] = true
PLOT_DEFAULTS[:yticks] = true PLOT_DEFAULTS[:yticks] = true
PLOT_DEFAULTS[:size] = (600,400)
# TODO: x/y scales # TODO: x/y scales

View File

@ -141,6 +141,7 @@ function plot!(pkg::PlottingPackage, plt::Plot, x::AMat, y::AMat; kw...)
end end
function plot!(pkg::PlottingPackage, plt::Plot, x::AVec, f::Function; kw...) # one line, y = f(x) 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)...) plot!(pkg, plt; x = x, y = map(f,x), getPlotKeywordArgs(kw, 1, plt)...)
end end
@ -153,13 +154,13 @@ function plot!(pkg::PlottingPackage, plt::Plot, x::AMat, f::Function; kw...)
plt plt
end end
function plot!(pkg::PlottingPackage, plt::Plot, x::AVec, fs::AVec{Function}; kw...) # multiple lines, yᵢⱼ = fⱼ(xᵢ) # function plot!(pkg::PlottingPackage, plt::Plot, x::AVec, fs::AVec{Function}; kw...) # multiple lines, yᵢⱼ = fⱼ(xᵢ)
for i in 1:length(fs) # for i in 1:length(fs)
plt.n += 1 # plt.n += 1
plot!(pkg, plt; x = x, y = map(fs[i], x), getPlotKeywordArgs(kw, i, plt)...) # plot!(pkg, plt; x = x, y = map(fs[i], x), getPlotKeywordArgs(kw, i, plt)...)
end # end
plt # plt
end # end
function plot!(pkg::PlottingPackage, plt::Plot, y::AVec; kw...) # multiple lines, each with x = 1:length(y[i]) function plot!(pkg::PlottingPackage, plt::Plot, y::AVec; kw...) # multiple lines, each with x = 1:length(y[i])
for i in 1:length(y) 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]) 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) for i in 1:length(y)
if typeof(y[i]) <: AbstractVector
@assert length(x) == length(y[i]) @assert length(x) == length(y[i])
plt.n += 1 plt.n += 1
plot!(pkg, plt; x = x, y = y[i], getPlotKeywordArgs(kw, i, plt)...) 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 end
plt plt
end end