examples
@ -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, "\n\n")
|
||||
write(md, "\n\n")
|
||||
|
||||
catch ex
|
||||
# TODO: put error info into markdown?
|
||||
|
||||
@ -6,17 +6,27 @@ A simple line plot of the 3 columns.
|
||||
plot(rand(100,3))
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
### Functions
|
||||
|
||||
Plot multiple functions
|
||||
|
||||
```julia
|
||||
plot(0:0.01:4π,[sin,cos])
|
||||
```
|
||||
|
||||

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

|
||||

|
||||
|
||||
### Vectors
|
||||
|
||||
@ -26,7 +36,7 @@ Plot multiple series with different numbers of points.
|
||||
plot(Vector[rand(10),rand(20)]; marker=:ellipse,markersize=8)
|
||||
```
|
||||
|
||||

|
||||

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

|
||||

|
||||
|
||||
|
||||
@ -6,17 +6,27 @@ A simple line plot of the 3 columns.
|
||||
plot(rand(100,3))
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
### Functions
|
||||
|
||||
Plot multiple functions
|
||||
|
||||
```julia
|
||||
plot(0:0.01:4π,[sin,cos])
|
||||
```
|
||||
|
||||

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

|
||||

|
||||
|
||||
### Vectors
|
||||
|
||||
@ -26,7 +36,7 @@ Plot multiple series with different numbers of points.
|
||||
plot(Vector[rand(10),rand(20)]; marker=:ellipse,markersize=8)
|
||||
```
|
||||
|
||||

|
||||

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

|
||||

|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 79 KiB |
BIN
img/gadfly_example_2.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 16 KiB |
BIN
img/qwt_example_2.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 11 KiB |
@ -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
|
||||
|
||||
|
||||
20
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)
|
||||
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
|
||||
|
||||