Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6ae0912e0e | |||
| e8062d544d | |||
| 07332aa4ac | |||
| 1e2b3559f2 | |||
| 8bfaa14edb | |||
| d4e87d3fe8 | |||
| 460348c0b6 | |||
| 264e8c735e | |||
| c4b04e2327 | |||
| dc1389bd1a | |||
| 51e38c80d8 | |||
| a33f5fabd1 | |||
| e6c8344970 | |||
| 2207ae6617 | |||
| cdc6707ad3 | |||
| 448fdaecbd | |||
| 4aa79aed6f | |||
| c8fcc373f8 | |||
| 1410141b46 | |||
| 76efabb5f3 | |||
| 36effc6dc4 | |||
| 8d5412a38f | |||
| 465b5d20b4 | |||
| 60a22b1897 | |||
| 09a685e977 | |||
| 31da90865c |
@@ -1,3 +1,4 @@
|
||||
*.jl.cov
|
||||
*.jl.*.cov
|
||||
*.jl.mem
|
||||
.DS_Store
|
||||
@@ -13,21 +13,25 @@ Please add wishlist items, bugs, or any other comments/questions to the issues l
|
||||
- [Qwt.jl](docs/qwt_examples.md)
|
||||
- [Gadfly.jl](docs/gadfly_examples.md)
|
||||
- [UnicodePlots.jl](docs/unicodeplots_examples.md)
|
||||
- [PyPlot.jl](docs/pyplot_examples.md)
|
||||
- [Immerse.jl](docs/immerse_examples.md)
|
||||
|
||||
## Installation
|
||||
|
||||
First, clone the package
|
||||
First, add the package
|
||||
|
||||
```julia
|
||||
Pkg.clone("https://github.com/tbreloff/Plots.jl.git")
|
||||
Pkg.add("Plots")
|
||||
```
|
||||
|
||||
then get any plotting packages you need (obviously, you should get at least one backend):
|
||||
|
||||
```julia
|
||||
Pkg.add("Gadfly") # [optional]
|
||||
Pkg.clone("https://github.com/tbreloff/Qwt.jl.git") # [optional] requires pyqt and pyqwt
|
||||
Pkg.add("UnicodePlots") # [optional]
|
||||
Pkg.add("Gadfly")
|
||||
Pkg.add("Immerse")
|
||||
Pkg.add("UnicodePlots")
|
||||
Pkg.add("PyPlot") # requires python and matplotlib
|
||||
Pkg.clone("https://github.com/tbreloff/Qwt.jl.git") # requires pyqt and pyqwt
|
||||
```
|
||||
|
||||
## Use
|
||||
@@ -43,8 +47,13 @@ using Plots
|
||||
Do a plot in Gadfly, then save a png:
|
||||
|
||||
```julia
|
||||
# switch to Gadfly as a backend
|
||||
gadfly!()
|
||||
plot(rand(10,2); marker = :rect) # this will bring up a browser window with the plot, set show=false if you don't want that
|
||||
|
||||
# This will bring up a browser window with the plot. Add a semicolon to skip display.
|
||||
plot(rand(10,2); marker = :rect, markersizes=[10,30])
|
||||
|
||||
# save it as a PNG
|
||||
savepng(Plots.IMG_DIR * "gadfly1.png")
|
||||
```
|
||||
|
||||
@@ -52,7 +61,7 @@ which saves:
|
||||
|
||||

|
||||
|
||||
See the examples pages for lots of ways to plot in every supported backend.
|
||||
See the examples pages for lots of examples of plots, and what those commands produce for each supported backend.
|
||||
|
||||
## API
|
||||
|
||||
@@ -179,7 +188,6 @@ size # (Int,Int), resize the enclosing window
|
||||
pos # (Int,Int), move the enclosing window to this position
|
||||
windowtitle # string or symbol, set the title of the enclosing windowtitle
|
||||
screen # Integer, move enclosing window to this screen number (for multiscreen desktops)
|
||||
show # true or false, show the plot (in case you don't want the window to pop up right away)
|
||||
```
|
||||
|
||||
Note that not every backend supports all options.
|
||||
@@ -204,11 +212,10 @@ xlabel = ""
|
||||
ylabel = ""
|
||||
yrightlabel = ""
|
||||
reg = false
|
||||
size = (800,600)
|
||||
size = (600,400)
|
||||
pos = (0,0)
|
||||
windowtitle = ""
|
||||
windowtitle = "Plots.jl"
|
||||
screen = 1
|
||||
show = true
|
||||
```
|
||||
|
||||
__Tip__: You can see the default value for a given argument with `plotDefault(arg::Symbol)`, and set the default value with `plotDefault!(arg::Symbol, value)`
|
||||
@@ -224,7 +231,7 @@ plot(rand(100,2); colors = [:red, RGB(.5,.5,0)],
|
||||
width = 5)
|
||||
```
|
||||
|
||||
# TODO
|
||||
## TODO features:
|
||||
|
||||
- [x] Plot vectors/matrices/functions
|
||||
- [ ] Plot DataFrames
|
||||
@@ -238,28 +245,32 @@ plot(rand(100,2); colors = [:red, RGB(.5,.5,0)],
|
||||
- [ ] Scenes/Drawing
|
||||
- [ ] Graphs
|
||||
- [ ] Interactivity (GUIs)
|
||||
|
||||
## TODO backends:
|
||||
|
||||
- [x] Gadfly.jl
|
||||
- [ ] PyPlot.jl
|
||||
- [ ] Winston.jl
|
||||
- [ ] Gaston.jl
|
||||
- [ ] GLPlot.jl
|
||||
- [x] Immerse.jl
|
||||
- [x] PyPlot.jl
|
||||
- [x] UnicodePlots.jl
|
||||
- [x] Qwt.jl
|
||||
- [ ] Winston.jl
|
||||
- [ ] GLPlot.jl
|
||||
- [ ] Bokeh.jl
|
||||
- [ ] Vega.jl
|
||||
- [ ] Gaston.jl
|
||||
- [ ] Plotly.jl
|
||||
- [ ] GoogleCharts.jl
|
||||
- [ ] Vega.jl
|
||||
- [ ] PLplot.jl
|
||||
- [ ] TextPlots.jl
|
||||
- [ ] ASCIIPlots.jl
|
||||
- [ ] Sparklines.jl
|
||||
- [x] UnicodePlots.jl
|
||||
- [ ] Hinton.jl
|
||||
- [ ] ImageTerm.jl
|
||||
- [ ] GraphViz.jl
|
||||
- [ ] TikzGraphs.jl
|
||||
- [ ] GraphLayout.jl
|
||||
|
||||
# More information on backends (both supported and unsupported)
|
||||
## More information on backends (both supported and unsupported)
|
||||
|
||||
See the wiki at: https://github.com/JuliaPlot/juliaplot_docs/wiki
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ const examples = PlotExample[
|
||||
[:(plot(rand(10); title="TITLE", xlabel="XLABEL", ylabel="YLABEL", background_color = RGB(0.5,0.5,0.5)))]),
|
||||
PlotExample("Two-axis",
|
||||
"Use the `axis` or `axiss` arguments.\n\nNote: This is only supported with Qwt right now",
|
||||
[:(plot(Vector[randn(100), randn(100)*100]; axiss = [:left,:right]))]),
|
||||
[:(plot(Vector[randn(100), randn(100)*100]; axiss = [:left,:right], ylabel="LEFT", yrightlabel="RIGHT"))]),
|
||||
PlotExample("Vectors w/ pluralized args",
|
||||
"Plot multiple series with different numbers of points. Mix arguments that apply to all series (singular... see `marker`) with arguments unique to each series (pluralized... see `colors`).",
|
||||
[:(plot(Vector[rand(10), rand(20)]; marker=:ellipse, markersize=8, colors=[:red,:blue]))]),
|
||||
@@ -48,10 +48,18 @@ const examples = PlotExample[
|
||||
[:(scatter!(rand(100); markersize=6, color=:blue))]),
|
||||
PlotExample("Heatmaps",
|
||||
"",
|
||||
[:(heatmap(randn(10000),randn(10000); nbins=200))]),
|
||||
[:(heatmap(randn(10000),randn(10000); nbins=100))]),
|
||||
PlotExample("Lots of line types",
|
||||
"Options: (:line, :step, :stepinverted, :sticks, :dots, :none, :heatmap, :hexbin, :hist, :bar) \nNote: some may not work with all backends",
|
||||
[:(plot(rand(20,4); linetypes=[:line, :step, :sticks, :dots], labels=["line","step","sticks","dots"]))]),
|
||||
PlotExample("Lots of line styles",
|
||||
"Options: (:solid, :dash, :dot, :dashdot, :dashdotdot) \nNote: some may not work with all backends",
|
||||
[:(plot(rand(20,5); linestyles=[:solid, :dash, :dot, :dashdot, :dashdotdot], labels=["solid", "dash", "dot", "dashdot", "dashdotdot"]))]),
|
||||
PlotExample("Lots of marker types",
|
||||
"Options: (:none, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon) \nNote: some may not work with all backends",
|
||||
[:(plot(repmat(collect(1:10)',10,1); markers=[:ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon],
|
||||
labels=["ellipse", "rect", "diamond", "utriangle", "dtriangle", "cross", "xcross", "star1", "star2", "hexagon"],
|
||||
markersize=10))]),
|
||||
PlotExample("Bar",
|
||||
"x is the midpoint of the bar. (todo: allow passing of edges instead of midpoints)",
|
||||
[:(bar(randn(1000)))]),
|
||||
@@ -82,7 +90,7 @@ function generate_markdown(pkgname::Symbol)
|
||||
|
||||
# set up the plotter, and don't show the plots by default
|
||||
plotter!(pkgname)
|
||||
plotDefault!(:show, false)
|
||||
# plotDefault!(:show, false)
|
||||
|
||||
# mkdir if necessary
|
||||
try
|
||||
@@ -123,9 +131,11 @@ end
|
||||
|
||||
# run it!
|
||||
# note: generate separately so it's easy to comment out
|
||||
generate_markdown(:qwt)
|
||||
# generate_markdown(:qwt)
|
||||
generate_markdown(:gadfly)
|
||||
generate_markdown(:unicodeplots)
|
||||
# @osx_only generate_markdown(:unicodeplots)
|
||||
# generate_markdown(:pyplot)
|
||||
generate_markdown(:immerse)
|
||||
|
||||
|
||||
end # module
|
||||
|
||||
@@ -33,7 +33,7 @@ plot([sin,cos],0,4π)
|
||||
Or make a parametric plot with plot(fx, fy, umin, umax).
|
||||
|
||||
```julia
|
||||
plot(sin,(x->begin # /Users/tom/.julia/v0.4/Plots/docs/example_generation.jl, line 33:
|
||||
plot(sin,(x->begin # /home/tom/.julia/v0.4/Plots/docs/example_generation.jl, line 33:
|
||||
sin(2x)
|
||||
end),0,2π)
|
||||
```
|
||||
@@ -57,7 +57,7 @@ Use the `axis` or `axiss` arguments.
|
||||
Note: This is only supported with Qwt right now
|
||||
|
||||
```julia
|
||||
plot(Vector[randn(100),randn(100) * 100]; axiss=[:left,:right])
|
||||
plot(Vector[randn(100),randn(100) * 100]; axiss=[:left,:right],ylabel="LEFT",yrightlabel="RIGHT")
|
||||
```
|
||||
|
||||

|
||||
@@ -97,7 +97,7 @@ scatter!(rand(100); markersize=6,color=:blue)
|
||||
|
||||
|
||||
```julia
|
||||
heatmap(randn(10000),randn(10000); nbins=200)
|
||||
heatmap(randn(10000),randn(10000); nbins=100)
|
||||
```
|
||||
|
||||

|
||||
@@ -113,6 +113,28 @@ plot(rand(20,4); linetypes=[:line,:step,:sticks,:dots],labels=["line","step","st
|
||||
|
||||

|
||||
|
||||
### Lots of line styles
|
||||
|
||||
Options: (:solid, :dash, :dot, :dashdot, :dashdotdot)
|
||||
Note: some may not work with all backends
|
||||
|
||||
```julia
|
||||
plot(rand(20,5); linestyles=[:solid,:dash,:dot,:dashdot,:dashdotdot],labels=["solid","dash","dot","dashdot","dashdotdot"])
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Lots of marker types
|
||||
|
||||
Options: (:none, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon)
|
||||
Note: some may not work with all backends
|
||||
|
||||
```julia
|
||||
plot(repmat(collect(1:10)',10,1); markers=[:ellipse,:rect,:diamond,:utriangle,:dtriangle,:cross,:xcross,:star1,:star2,:hexagon],labels=["ellipse","rect","diamond","utriangle","dtriangle","cross","xcross","star1","star2","hexagon"],markersize=10)
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Bar
|
||||
|
||||
x is the midpoint of the bar. (todo: allow passing of edges instead of midpoints)
|
||||
@@ -121,7 +143,7 @@ x is the midpoint of the bar. (todo: allow passing of edges instead of midpoints
|
||||
bar(randn(1000))
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
### Histogram
|
||||
|
||||
@@ -131,7 +153,7 @@ note: fillto isn't supported on all backends
|
||||
histogram(randn(1000); nbins=50,fillto=20)
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
### Subplots
|
||||
|
||||
@@ -146,7 +168,7 @@ histogram(randn(1000); nbins=50,fillto=20)
|
||||
subplot(randn(100,5); layout=[1,1,3],linetypes=[:line,:hist,:dots,:step,:bar],nbins=10,legend=false)
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
### Adding to subplots
|
||||
|
||||
@@ -156,7 +178,7 @@ Note here the automatic grid layout, as well as the order in which new series ar
|
||||
subplot(randn(100,5); n=4)
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
###
|
||||
|
||||
@@ -166,5 +188,5 @@ subplot(randn(100,5); n=4)
|
||||
subplot!(randn(100,3))
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
|
||||
@@ -0,0 +1,192 @@
|
||||
### Lines
|
||||
|
||||
A simple line plot of the 3 columns.
|
||||
|
||||
```julia
|
||||
plot(rand(100,3))
|
||||
```
|
||||
|
||||

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

|
||||
|
||||
###
|
||||
|
||||
You can also call it with plot(f, xmin, xmax).
|
||||
|
||||
```julia
|
||||
plot([sin,cos],0,4π)
|
||||
```
|
||||
|
||||

|
||||
|
||||
###
|
||||
|
||||
Or make a parametric plot with plot(fx, fy, umin, umax).
|
||||
|
||||
```julia
|
||||
plot(sin,(x->begin # /home/tom/.julia/v0.4/Plots/docs/example_generation.jl, line 33:
|
||||
sin(2x)
|
||||
end),0,2π)
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Global
|
||||
|
||||
Change the guides/background without a separate call.
|
||||
|
||||
```julia
|
||||
plot(rand(10); title="TITLE",xlabel="XLABEL",ylabel="YLABEL",background_color=RGB(0.5,0.5,0.5))
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Two-axis
|
||||
|
||||
Use the `axis` or `axiss` arguments.
|
||||
|
||||
Note: This is only supported with Qwt right now
|
||||
|
||||
```julia
|
||||
plot(Vector[randn(100),randn(100) * 100]; axiss=[:left,:right],ylabel="LEFT",yrightlabel="RIGHT")
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Vectors w/ pluralized args
|
||||
|
||||
Plot multiple series with different numbers of points. Mix arguments that apply to all series (singular... see `marker`) with arguments unique to each series (pluralized... see `colors`).
|
||||
|
||||
```julia
|
||||
plot(Vector[rand(10),rand(20)]; marker=:ellipse,markersize=8,colors=[:red,:blue])
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Build plot in pieces
|
||||
|
||||
Start with a base plot...
|
||||
|
||||
```julia
|
||||
plot(rand(100) / 3; reg=true,fillto=0)
|
||||
```
|
||||
|
||||

|
||||
|
||||
###
|
||||
|
||||
and add to it later.
|
||||
|
||||
```julia
|
||||
scatter!(rand(100); markersize=6,color=:blue)
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Heatmaps
|
||||
|
||||
|
||||
|
||||
```julia
|
||||
heatmap(randn(10000),randn(10000); nbins=100)
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Lots of line types
|
||||
|
||||
Options: (:line, :step, :stepinverted, :sticks, :dots, :none, :heatmap, :hexbin, :hist, :bar)
|
||||
Note: some may not work with all backends
|
||||
|
||||
```julia
|
||||
plot(rand(20,4); linetypes=[:line,:step,:sticks,:dots],labels=["line","step","sticks","dots"])
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Lots of line styles
|
||||
|
||||
Options: (:solid, :dash, :dot, :dashdot, :dashdotdot)
|
||||
Note: some may not work with all backends
|
||||
|
||||
```julia
|
||||
plot(rand(20,5); linestyles=[:solid,:dash,:dot,:dashdot,:dashdotdot],labels=["solid","dash","dot","dashdot","dashdotdot"])
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Lots of marker types
|
||||
|
||||
Options: (:none, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon)
|
||||
Note: some may not work with all backends
|
||||
|
||||
```julia
|
||||
plot(repmat(collect(1:10)',10,1); markers=[:ellipse,:rect,:diamond,:utriangle,:dtriangle,:cross,:xcross,:star1,:star2,:hexagon],labels=["ellipse","rect","diamond","utriangle","dtriangle","cross","xcross","star1","star2","hexagon"],markersize=10)
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Bar
|
||||
|
||||
x is the midpoint of the bar. (todo: allow passing of edges instead of midpoints)
|
||||
|
||||
```julia
|
||||
bar(randn(1000))
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Histogram
|
||||
|
||||
note: fillto isn't supported on all backends
|
||||
|
||||
```julia
|
||||
histogram(randn(1000); nbins=50,fillto=20)
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Subplots
|
||||
|
||||
subplot and subplot! are distinct commands which create many plots and add series to them in a circular fashion.
|
||||
You can define the layout with keyword params... either set the number of plots `n` (and optionally number of rows `nr` or
|
||||
number of columns `nc`), or you can set the layout directly with `layout`.
|
||||
|
||||
Note: Gadfly is not very friendly here, and although you can create a plot and save a PNG, I haven't been able to actually display it.
|
||||
|
||||
|
||||
```julia
|
||||
subplot(randn(100,5); layout=[1,1,3],linetypes=[:line,:hist,:dots,:step,:bar],nbins=10,legend=false)
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Adding to subplots
|
||||
|
||||
Note here the automatic grid layout, as well as the order in which new series are added to the plots.
|
||||
|
||||
```julia
|
||||
subplot(randn(100,5); n=4)
|
||||
```
|
||||
|
||||

|
||||
|
||||
###
|
||||
|
||||
|
||||
|
||||
```julia
|
||||
subplot!(randn(100,3))
|
||||
```
|
||||
|
||||

|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
### Lines
|
||||
|
||||
A simple line plot of the 3 columns.
|
||||
|
||||
```julia
|
||||
plot(rand(100,3))
|
||||
```
|
||||
|
||||

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

|
||||
|
||||
###
|
||||
|
||||
You can also call it with plot(f, xmin, xmax).
|
||||
|
||||
```julia
|
||||
plot([sin,cos],0,4π)
|
||||
```
|
||||
|
||||

|
||||
|
||||
###
|
||||
|
||||
Or make a parametric plot with plot(fx, fy, umin, umax).
|
||||
|
||||
```julia
|
||||
plot(sin,(x->begin # /Users/tom/.julia/v0.4/Plots/docs/example_generation.jl, line 33:
|
||||
sin(2x)
|
||||
end),0,2π)
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Global
|
||||
|
||||
Change the guides/background without a separate call.
|
||||
|
||||
```julia
|
||||
plot(rand(10); title="TITLE",xlabel="XLABEL",ylabel="YLABEL",background_color=RGB(0.5,0.5,0.5))
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Two-axis
|
||||
|
||||
Use the `axis` or `axiss` arguments.
|
||||
|
||||
Note: This is only supported with Qwt right now
|
||||
|
||||
```julia
|
||||
plot(Vector[randn(100),randn(100) * 100]; axiss=[:left,:right],ylabel="LEFT",yrightlabel="RIGHT")
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Vectors w/ pluralized args
|
||||
|
||||
Plot multiple series with different numbers of points. Mix arguments that apply to all series (singular... see `marker`) with arguments unique to each series (pluralized... see `colors`).
|
||||
|
||||
```julia
|
||||
plot(Vector[rand(10),rand(20)]; marker=:ellipse,markersize=8,colors=[:red,:blue])
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Build plot in pieces
|
||||
|
||||
Start with a base plot...
|
||||
|
||||
```julia
|
||||
plot(rand(100) / 3; reg=true,fillto=0)
|
||||
```
|
||||
|
||||

|
||||
|
||||
###
|
||||
|
||||
and add to it later.
|
||||
|
||||
```julia
|
||||
scatter!(rand(100); markersize=6,color=:blue)
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Heatmaps
|
||||
|
||||
|
||||
|
||||
```julia
|
||||
heatmap(randn(10000),randn(10000); nbins=100)
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Lots of line types
|
||||
|
||||
Options: (:line, :step, :stepinverted, :sticks, :dots, :none, :heatmap, :hexbin, :hist, :bar)
|
||||
Note: some may not work with all backends
|
||||
|
||||
```julia
|
||||
plot(rand(20,4); linetypes=[:line,:step,:sticks,:dots],labels=["line","step","sticks","dots"])
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Lots of line styles
|
||||
|
||||
Options: (:solid, :dash, :dot, :dashdot, :dashdotdot)
|
||||
Note: some may not work with all backends
|
||||
|
||||
```julia
|
||||
plot(rand(20,5); linestyles=[:solid,:dash,:dot,:dashdot,:dashdotdot],labels=["solid","dash","dot","dashdot","dashdotdot"])
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Lots of marker types
|
||||
|
||||
Options: (:none, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon)
|
||||
Note: some may not work with all backends
|
||||
|
||||
```julia
|
||||
plot(repmat(collect(1:10)',10,1); markers=[:ellipse,:rect,:diamond,:utriangle,:dtriangle,:cross,:xcross,:star1,:star2,:hexagon],labels=["ellipse","rect","diamond","utriangle","dtriangle","cross","xcross","star1","star2","hexagon"],linetype=:none,markersize=10)
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Bar
|
||||
|
||||
x is the midpoint of the bar. (todo: allow passing of edges instead of midpoints)
|
||||
|
||||
```julia
|
||||
bar(randn(1000))
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Histogram
|
||||
|
||||
note: fillto isn't supported on all backends
|
||||
|
||||
```julia
|
||||
histogram(randn(1000); nbins=50,fillto=20)
|
||||
```
|
||||
|
||||

|
||||
|
||||
@@ -33,7 +33,7 @@ plot([sin,cos],0,4π)
|
||||
Or make a parametric plot with plot(fx, fy, umin, umax).
|
||||
|
||||
```julia
|
||||
plot(sin,(x->begin # /Users/tom/.julia/v0.4/Plots/docs/example_generation.jl, line 33:
|
||||
plot(sin,(x->begin # /home/tom/.julia/v0.4/Plots/docs/example_generation.jl, line 33:
|
||||
sin(2x)
|
||||
end),0,2π)
|
||||
```
|
||||
@@ -57,7 +57,7 @@ Use the `axis` or `axiss` arguments.
|
||||
Note: This is only supported with Qwt right now
|
||||
|
||||
```julia
|
||||
plot(Vector[randn(100),randn(100) * 100]; axiss=[:left,:right])
|
||||
plot(Vector[randn(100),randn(100) * 100]; axiss=[:left,:right],ylabel="LEFT",yrightlabel="RIGHT")
|
||||
```
|
||||
|
||||

|
||||
@@ -97,7 +97,7 @@ scatter!(rand(100); markersize=6,color=:blue)
|
||||
|
||||
|
||||
```julia
|
||||
heatmap(randn(10000),randn(10000); nbins=200)
|
||||
heatmap(randn(10000),randn(10000); nbins=100)
|
||||
```
|
||||
|
||||

|
||||
@@ -113,6 +113,28 @@ plot(rand(20,4); linetypes=[:line,:step,:sticks,:dots],labels=["line","step","st
|
||||
|
||||

|
||||
|
||||
### Lots of line styles
|
||||
|
||||
Options: (:solid, :dash, :dot, :dashdot, :dashdotdot)
|
||||
Note: some may not work with all backends
|
||||
|
||||
```julia
|
||||
plot(rand(20,5); linestyles=[:solid,:dash,:dot,:dashdot,:dashdotdot],labels=["solid","dash","dot","dashdot","dashdotdot"])
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Lots of marker types
|
||||
|
||||
Options: (:none, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon)
|
||||
Note: some may not work with all backends
|
||||
|
||||
```julia
|
||||
plot(repmat(collect(1:10)',10,1); markers=[:ellipse,:rect,:diamond,:utriangle,:dtriangle,:cross,:xcross,:star1,:star2,:hexagon],labels=["ellipse","rect","diamond","utriangle","dtriangle","cross","xcross","star1","star2","hexagon"],linetype=:none,markersize=10)
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Bar
|
||||
|
||||
x is the midpoint of the bar. (todo: allow passing of edges instead of midpoints)
|
||||
@@ -121,7 +143,7 @@ x is the midpoint of the bar. (todo: allow passing of edges instead of midpoints
|
||||
bar(randn(1000))
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
### Histogram
|
||||
|
||||
@@ -131,7 +153,7 @@ note: fillto isn't supported on all backends
|
||||
histogram(randn(1000); nbins=50,fillto=20)
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
### Subplots
|
||||
|
||||
@@ -146,7 +168,7 @@ histogram(randn(1000); nbins=50,fillto=20)
|
||||
subplot(randn(100,5); layout=[1,1,3],linetypes=[:line,:hist,:dots,:step,:bar],nbins=10,legend=false)
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
### Adding to subplots
|
||||
|
||||
@@ -156,7 +178,7 @@ Note here the automatic grid layout, as well as the order in which new series ar
|
||||
subplot(randn(100,5); n=4)
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
###
|
||||
|
||||
@@ -166,5 +188,5 @@ subplot(randn(100,5); n=4)
|
||||
subplot!(randn(100,3))
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ Use the `axis` or `axiss` arguments.
|
||||
Note: This is only supported with Qwt right now
|
||||
|
||||
```julia
|
||||
plot(Vector[randn(100),randn(100) * 100]; axiss=[:left,:right])
|
||||
plot(Vector[randn(100),randn(100) * 100]; axiss=[:left,:right],ylabel="LEFT",yrightlabel="RIGHT")
|
||||
```
|
||||
|
||||

|
||||
@@ -103,6 +103,28 @@ plot(rand(20,4); linetypes=[:line,:step,:sticks,:dots],labels=["line","step","st
|
||||
|
||||

|
||||
|
||||
### Lots of line styles
|
||||
|
||||
Options: (:solid, :dash, :dot, :dashdot, :dashdotdot)
|
||||
Note: some may not work with all backends
|
||||
|
||||
```julia
|
||||
plot(rand(20,5); linestyles=[:solid,:dash,:dot,:dashdot,:dashdotdot],labels=["solid","dash","dot","dashdot","dashdotdot"])
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Lots of marker types
|
||||
|
||||
Options: (:none, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon)
|
||||
Note: some may not work with all backends
|
||||
|
||||
```julia
|
||||
plot(repmat(collect(1:10)',10,1); markers=[:ellipse,:rect,:diamond,:utriangle,:dtriangle,:cross,:xcross,:star1,:star2,:hexagon],labels=["ellipse","rect","diamond","utriangle","dtriangle","cross","xcross","star1","star2","hexagon"],linetype=:none,markersize=10)
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Bar
|
||||
|
||||
x is the midpoint of the bar. (todo: allow passing of edges instead of midpoints)
|
||||
@@ -111,7 +133,7 @@ x is the midpoint of the bar. (todo: allow passing of edges instead of midpoints
|
||||
bar(randn(1000))
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
### Histogram
|
||||
|
||||
@@ -121,7 +143,7 @@ note: fillto isn't supported on all backends
|
||||
histogram(randn(1000); nbins=50,fillto=20)
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
### Subplots
|
||||
|
||||
@@ -136,7 +158,7 @@ histogram(randn(1000); nbins=50,fillto=20)
|
||||
subplot(randn(100,5); layout=[1,1,3],linetypes=[:line,:hist,:dots,:step,:bar],nbins=10,legend=false)
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
### Adding to subplots
|
||||
|
||||
@@ -146,7 +168,7 @@ Note here the automatic grid layout, as well as the order in which new series ar
|
||||
subplot(randn(100,5); n=4)
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
###
|
||||
|
||||
@@ -156,5 +178,5 @@ subplot(randn(100,5); n=4)
|
||||
subplot!(randn(100,3))
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 84 KiB After Width: | Height: | Size: 77 KiB |
|
Before Width: | Height: | Size: 103 KiB After Width: | Height: | Size: 87 KiB |
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 63 KiB |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 44 KiB |
|
After Width: | Height: | Size: 56 KiB |
|
After Width: | Height: | Size: 77 KiB |
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 81 KiB |
|
After Width: | Height: | Size: 83 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 64 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 42 KiB |
|
After Width: | Height: | Size: 62 KiB |
|
After Width: | Height: | Size: 82 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 42 KiB |
|
After Width: | Height: | Size: 39 KiB |
|
After Width: | Height: | Size: 90 KiB |
|
After Width: | Height: | Size: 199 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 70 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 43 KiB |
|
After Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 73 KiB |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 52 KiB |
|
Before Width: | Height: | Size: 6.2 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 9.4 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 42 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 101 KiB |
|
Before Width: | Height: | Size: 8.3 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 7.9 KiB After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 9.7 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 42 KiB |
|
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 9.4 KiB After Width: | Height: | Size: 43 KiB |
|
Before Width: | Height: | Size: 9.1 KiB After Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 142 KiB After Width: | Height: | Size: 147 KiB |
|
Before Width: | Height: | Size: 101 KiB After Width: | Height: | Size: 95 KiB |
|
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 114 KiB |
|
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 47 KiB |
|
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 70 KiB |
|
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 57 KiB |
|
Before Width: | Height: | Size: 94 KiB After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 67 KiB |
|
After Width: | Height: | Size: 94 KiB |
|
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 52 KiB |
|
Before Width: | Height: | Size: 69 KiB After Width: | Height: | Size: 65 KiB |
|
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 64 KiB |
|
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 80 KiB |
|
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 57 KiB |
@@ -32,7 +32,9 @@ export
|
||||
backends,
|
||||
qwt!,
|
||||
gadfly!,
|
||||
unicodeplots!
|
||||
unicodeplots!,
|
||||
pyplot!,
|
||||
immerse!
|
||||
|
||||
# ---------------------------------------------------------
|
||||
|
||||
@@ -67,6 +69,7 @@ heatmap!(args...; kw...) = plot!(args...; kw..., linetype = :heatmap)
|
||||
|
||||
savepng(args...; kw...) = savepng(currentPlot(), args...; kw...)
|
||||
savepng(plt::PlottingObject, args...; kw...) = savepng(plt.plotter, plt, args...; kw...)
|
||||
savepng(::PlottingPackage, plt::PlottingObject, fn::String, args...) = error("unsupported") # fallback so multiple dispatch doesn't get confused if it's missing
|
||||
|
||||
|
||||
# ---------------------------------------------------------
|
||||
|
||||
@@ -40,6 +40,12 @@ PLOT_DEFAULTS[:legend] = true
|
||||
PLOT_DEFAULTS[:xticks] = true
|
||||
PLOT_DEFAULTS[:yticks] = true
|
||||
PLOT_DEFAULTS[:size] = (600,400)
|
||||
PLOT_DEFAULTS[:windowtitle] = "Plots.jl"
|
||||
# PLOT_DEFAULTS[:show] = true
|
||||
|
||||
PLOT_DEFAULTS[:args] = [] # additional args to pass to the backend
|
||||
PLOT_DEFAULTS[:kwargs] = [] # additional keyword args to pass to the backend
|
||||
# note: can be Vector{Dict} or Vector{Tuple}
|
||||
|
||||
# TODO: x/y scales
|
||||
|
||||
@@ -81,11 +87,21 @@ function getRGBColor(c, n::Int = 0)
|
||||
c
|
||||
end
|
||||
|
||||
# const ALT_ARG_NAMES = Dict{Tuple{Symbol,Symbol}, Any}()
|
||||
# ALT_ARG_NAMES[(:linetype, :scatter)] = :dots
|
||||
|
||||
|
||||
# note: idx is the index of this series within this call, n is the index of the series from all calls to plot/subplot
|
||||
function getPlotKeywordArgs(kw, idx::Int, n::Int)
|
||||
d = Dict(kw)
|
||||
|
||||
# # replace alternate names
|
||||
# for tup in kw
|
||||
# if haskey(ALT_ARG_NAMES, tup)
|
||||
# d[tup[1]] = ALT_ARG_NAMES[tup]
|
||||
# end
|
||||
# end
|
||||
|
||||
# default to a white background, but only on the initial call (so we don't change the background automatically)
|
||||
if haskey(d, :background_color)
|
||||
d[:background_color] = getRGBColor(d[:background_color])
|
||||
@@ -104,6 +120,14 @@ function getPlotKeywordArgs(kw, idx::Int, n::Int)
|
||||
delete!(d, plural)
|
||||
end
|
||||
|
||||
# swap out dots for no line and a marker
|
||||
if haskey(d, :linetype) && d[:linetype] == :dots
|
||||
d[:linetype] = :none
|
||||
if d[:marker] == :none
|
||||
d[:marker] = :ellipse
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
# handle plot initialization differently
|
||||
|
||||
@@ -6,105 +6,148 @@ immutable GadflyPackage <: PlottingPackage end
|
||||
gadfly!() = plotter!(:gadfly)
|
||||
|
||||
|
||||
# create a blank Gadfly.Plot object
|
||||
function plot(pkg::GadflyPackage; kw...)
|
||||
|
||||
function createGadflyPlotObject(d::Dict)
|
||||
@eval import DataFrames
|
||||
|
||||
plt = Gadfly.Plot()
|
||||
plt.mapping = Dict()
|
||||
plt.data_source = DataFrames.DataFrame()
|
||||
plt.layers = plt.layers[1:0]
|
||||
gplt = Gadfly.Plot()
|
||||
gplt.mapping = Dict()
|
||||
gplt.data_source = DataFrames.DataFrame()
|
||||
gplt.layers = gplt.layers[1:0]
|
||||
|
||||
# add the title, axis labels, and theme
|
||||
d = Dict(kw)
|
||||
|
||||
plt.guides = Gadfly.GuideElement[Gadfly.Guide.xlabel(d[:xlabel]),
|
||||
gplt.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[]))
|
||||
unshift!(gplt.guides, Gadfly.Guide.manual_color_key("", AbstractString[], Color[]))
|
||||
end
|
||||
|
||||
plt.theme = Gadfly.Theme(background_color = (haskey(d, :background_color) ? d[:background_color] : colorant"white"))
|
||||
|
||||
Plot(plt, pkg, 0, d, Dict[])
|
||||
gplt.theme = Gadfly.Theme(background_color = (haskey(d, :background_color) ? d[:background_color] : colorant"white"))
|
||||
gplt
|
||||
end
|
||||
|
||||
function getGeomFromLineType(linetype::Symbol, nbins::Int)
|
||||
linetype == :line && return Gadfly.Geom.line
|
||||
linetype == :dots && return Gadfly.Geom.point
|
||||
linetype == :bar && return Gadfly.Geom.bar
|
||||
linetype == :step && return Gadfly.Geom.step
|
||||
linetype == :hist && return Gadfly.Geom.histogram(bincount=nbins)
|
||||
linetype == :none && return Gadfly.Geom.point # change this? are we usually pairing no line with scatterplots?
|
||||
linetype == :sticks && return Gadfly.Geom.bar
|
||||
error("linetype $linetype not currently supported with Gadfly")
|
||||
|
||||
# function getGeoms(linetype::Symbol, marker::Symbol, markercolor::Colorant, nbins::Int)
|
||||
function getLineGeoms(d::Dict)
|
||||
lt = d[:linetype]
|
||||
lt in (:heatmap,:hexbin) && return [Gadfly.Geom.hexbin(xbincount = d[:nbins], ybincount = d[:nbins])]
|
||||
lt == :hist && return [Gadfly.Geom.histogram(bincount = d[:nbins])]
|
||||
lt == :none && return [Gadfly.Geom.path]
|
||||
lt == :line && return [Gadfly.Geom.path]
|
||||
# lt == :dots && return [Gadfly.Geom.point]
|
||||
lt == :bar && return [Gadfly.Geom.bar]
|
||||
lt == :step && return [Gadfly.Geom.step]
|
||||
lt == :sticks && return [Gadfly.Geom.bar]
|
||||
error("linetype $lt not currently supported with Gadfly")
|
||||
end
|
||||
|
||||
function getGeoms(linetype::Symbol, marker::Symbol, nbins::Int)
|
||||
geoms = []
|
||||
|
||||
# handle heatmaps (hexbins) specially
|
||||
if linetype in (:heatmap,:hexbin)
|
||||
push!(geoms, Gadfly.Geom.hexbin(xbincount=nbins, ybincount=nbins))
|
||||
|
||||
# serious hack (I think?) to draw my own shapes as annotations... will it work? who knows...
|
||||
function getMarkerGeomsAndGuides(d::Dict)
|
||||
marker = d[:marker]
|
||||
if marker == :none
|
||||
return [],[]
|
||||
|
||||
# special handling for other marker shapes... gotta create Compose contexts and map them to series points using Guide.Annotation
|
||||
elseif marker == :rect
|
||||
# get the width/height of the square (both are sz)
|
||||
sz = d[:markersize] * Gadfly.px
|
||||
halfsz = sz/2
|
||||
|
||||
# remap x/y to the corner position of the squares
|
||||
xs = map(z -> Gadfly.Compose.Measure(;cx=z) - halfsz, float(d[:x]))
|
||||
ys = map(z -> Gadfly.Compose.Measure(;cy=z) + halfsz, float(d[:y]))
|
||||
|
||||
# return an Annotation which will add those shapes to each point in the series
|
||||
return [], [Gadfly.Guide.annotation(Gadfly.compose(Gadfly.context(), Gadfly.rectangle(xs,ys,[sz],[sz]), Gadfly.fill(d[:markercolor]), Gadfly.stroke(nothing)))]
|
||||
|
||||
else
|
||||
# make circles
|
||||
sz = 0.5 * d[:markersize] * Gadfly.px
|
||||
xs = collect(float(d[:x]))
|
||||
ys = collect(float(d[:y]))
|
||||
|
||||
# for other linetypes, get the correct Geom
|
||||
push!(geoms, getGeomFromLineType(linetype, nbins))
|
||||
# return an Annotation which will add those shapes to each point in the series
|
||||
return [], [Gadfly.Guide.annotation(Gadfly.compose(Gadfly.context(), Gadfly.circle(xs,ys,[sz]), Gadfly.fill(d[:markercolor]), Gadfly.stroke(nothing)))]
|
||||
|
||||
# for any marker, add Geom.point
|
||||
if marker != :none
|
||||
push!(geoms, Gadfly.Geom.point)
|
||||
end
|
||||
end
|
||||
|
||||
geoms
|
||||
# otherwise just return a Geom.point
|
||||
# [Gadfly.Geom.point], []
|
||||
end
|
||||
|
||||
|
||||
# plot one data series
|
||||
function plot!(::GadflyPackage, plt::Plot; kw...)
|
||||
d = Dict(kw)
|
||||
|
||||
function addGadflySeries!(gplt, d::Dict)
|
||||
gfargs = []
|
||||
|
||||
# add the Geoms
|
||||
append!(gfargs, getGeoms(d[:linetype], d[:marker], d[:nbins]))
|
||||
|
||||
# set color, line width, and point size
|
||||
theme = Gadfly.Theme(default_color = d[:color],
|
||||
line_width = d[:width] * Gadfly.px,
|
||||
default_point_size = d[:markersize] * Gadfly.px)
|
||||
push!(gfargs, theme)
|
||||
append!(gfargs, getLineGeoms(d)) #[:linetype], d[:marker], d[:markercolor], d[:nbins]))
|
||||
|
||||
# handle markers
|
||||
geoms, guides = getMarkerGeomsAndGuides(d)
|
||||
append!(gfargs, geoms)
|
||||
append!(gplt.guides, guides)
|
||||
|
||||
# add a regression line?
|
||||
if d[:reg]
|
||||
push!(gfargs, Gadfly.Geom.smooth(method=:lm))
|
||||
end
|
||||
|
||||
# add to the legend
|
||||
if length(gplt.guides) > 0 && isa(gplt.guides[1], Gadfly.Guide.ManualColorKey)
|
||||
push!(gplt.guides[1].labels, d[:label])
|
||||
push!(gplt.guides[1].colors, d[:marker] == :none ? d[:color] : d[:markercolor])
|
||||
end
|
||||
|
||||
|
||||
# # if we haven't added any geoms, we're probably just going to use annotations?
|
||||
# isempty(gfargs) && return
|
||||
|
||||
|
||||
# set theme: color, line width, and point size
|
||||
line_width = d[:width] * (d[:linetype] == :none ? 0 : 1) * Gadfly.px # 0 width when we don't show a line
|
||||
theme = Gadfly.Theme(default_color = d[:color],
|
||||
line_width = line_width,
|
||||
default_point_size = 0.5 * d[:markersize] * Gadfly.px)
|
||||
push!(gfargs, theme)
|
||||
|
||||
# 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
|
||||
|
||||
# save the kw args
|
||||
push!(plt.seriesargs, d)
|
||||
|
||||
# add the layer to the Gadfly.Plot
|
||||
prepend!(plt.o.layers, Gadfly.layer(unique(gfargs)...; x = x, y = d[:y]))
|
||||
prepend!(gplt.layers, Gadfly.layer(unique(gfargs)..., d[:args]...; x = x, y = d[:y], d[:kwargs]...))
|
||||
nothing
|
||||
end
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
# create a blank Gadfly.Plot object
|
||||
function plot(pkg::GadflyPackage; kw...)
|
||||
d = Dict(kw)
|
||||
gplt = createGadflyPlotObject(d)
|
||||
Plot(gplt, pkg, 0, d, Dict[])
|
||||
end
|
||||
|
||||
|
||||
# plot one data series
|
||||
function plot!(::GadflyPackage, plt::Plot; kw...)
|
||||
d = Dict(kw)
|
||||
addGadflySeries!(plt.o, d)
|
||||
push!(plt.seriesargs, d)
|
||||
plt
|
||||
end
|
||||
|
||||
|
||||
function Base.display(::GadflyPackage, plt::Plot)
|
||||
display(plt.o)
|
||||
end
|
||||
@@ -114,24 +157,33 @@ end
|
||||
function savepng(::GadflyPackage, plt::PlottingObject, fn::String;
|
||||
w = 6 * Gadfly.inch,
|
||||
h = 4 * Gadfly.inch)
|
||||
Gadfly.draw(Gadfly.PNG(fn, w, h), plt.o)
|
||||
o = getGadflyContext(plt.plotter, plt)
|
||||
Gadfly.draw(Gadfly.PNG(fn, w, h), o)
|
||||
end
|
||||
|
||||
|
||||
# -------------------------------
|
||||
|
||||
# create the underlying object (each backend will do this differently)
|
||||
function buildSubplotObject!(::GadflyPackage, subplt::Subplot)
|
||||
getGadflyContext(::GadflyPackage, plt::Plot) = plt.o
|
||||
getGadflyContext(::GadflyPackage, subplt::Subplot) = buildGadflySubplotContext(subplt)
|
||||
|
||||
# create my Compose.Context grid by hstacking and vstacking the Gadfly.Plot objects
|
||||
function buildGadflySubplotContext(subplt::Subplot)
|
||||
i = 0
|
||||
rows = []
|
||||
for rowcnt in subplt.layout.rowcounts
|
||||
push!(rows, Gadfly.hstack([plt.o for plt in subplt.plts[(1:rowcnt) + i]]...))
|
||||
push!(rows, Gadfly.hstack([getGadflyContext(plt.plotter, plt) for plt in subplt.plts[(1:rowcnt) + i]]...))
|
||||
i += rowcnt
|
||||
end
|
||||
subplt.o = Gadfly.vstack(rows...)
|
||||
Gadfly.vstack(rows...)
|
||||
end
|
||||
|
||||
# create the underlying object (each backend will do this differently)
|
||||
function buildSubplotObject!(::GadflyPackage, subplt::Subplot)
|
||||
subplt.o = nothing
|
||||
end
|
||||
|
||||
|
||||
function Base.display(::GadflyPackage, subplt::Subplot)
|
||||
display(subplt.o)
|
||||
display(buildGadflySubplotContext(subplt))
|
||||
end
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
|
||||
# https://github.com/JuliaGraphics/Immerse.jl
|
||||
|
||||
immutable ImmersePackage <: PlottingPackage end
|
||||
|
||||
immerse!() = plotter!(:immerse)
|
||||
|
||||
|
||||
function createImmerseFigure(d::Dict)
|
||||
# println("Creating immerse figure: ", d)
|
||||
w,h = d[:size]
|
||||
figidx = Immerse.figure(; name = d[:windowtitle], width = w, height = h)
|
||||
Immerse.Figure(figidx)
|
||||
end
|
||||
|
||||
|
||||
# create a blank Gadfly.Plot object
|
||||
function plot(pkg::ImmersePackage; kw...)
|
||||
d = Dict(kw)
|
||||
|
||||
# create the underlying Gadfly.Plot object
|
||||
gplt = createGadflyPlotObject(d)
|
||||
|
||||
# save both the Immerse.Figure and the Gadfly.Plot
|
||||
Plot((nothing,gplt), pkg, 0, d, Dict[])
|
||||
end
|
||||
|
||||
|
||||
# plot one data series
|
||||
function plot!(::ImmersePackage, plt::Plot; kw...)
|
||||
d = Dict(kw)
|
||||
gplt = plt.o[2]
|
||||
addGadflySeries!(gplt, d)
|
||||
push!(plt.seriesargs, d)
|
||||
plt
|
||||
end
|
||||
|
||||
function Base.display(::ImmersePackage, plt::Plot)
|
||||
|
||||
fig, gplt = plt.o
|
||||
if fig == nothing
|
||||
fig = createImmerseFigure(plt.initargs)
|
||||
plt.o = (fig, gplt)
|
||||
end
|
||||
|
||||
# display a new Figure object to force a redraw
|
||||
display(Immerse.Figure(fig.canvas, gplt))
|
||||
end
|
||||
|
||||
# -------------------------------
|
||||
|
||||
getGadflyContext(::ImmersePackage, plt::Plot) = plt.o[2]
|
||||
getGadflyContext(::ImmersePackage, subplt::Subplot) = buildGadflySubplotContext(subplt)
|
||||
|
||||
function savepng(::ImmersePackage, plt::PlottingObject, fn::String;
|
||||
w = 6 * Immerse.inch,
|
||||
h = 4 * Immerse.inch)
|
||||
gctx = getGadflyContext(plt.plotter, plt)
|
||||
Gadfly.draw(Gadfly.PNG(fn, w, h), gctx)
|
||||
nothing
|
||||
end
|
||||
|
||||
|
||||
# -------------------------------
|
||||
|
||||
|
||||
# function buildSubplotObject!(::ImmersePackage, subplt::Subplot)
|
||||
# end
|
||||
|
||||
|
||||
# create the underlying object
|
||||
function buildSubplotObject!(::ImmersePackage, subplt::Subplot)
|
||||
subplt.o = (nothing, nothing)
|
||||
end
|
||||
|
||||
|
||||
function Base.display(::ImmersePackage, subplt::Subplot)
|
||||
|
||||
fig, gctx = subplt.o
|
||||
if fig == nothing
|
||||
fig = createImmerseFigure(subplt.initargs)
|
||||
subplt.o = (fig, gctx)
|
||||
end
|
||||
|
||||
newfig = Immerse.Figure(fig.canvas)
|
||||
newfig.cc = buildGadflySubplotContext(subplt)
|
||||
display(newfig)
|
||||
end
|
||||
@@ -0,0 +1,202 @@
|
||||
|
||||
# https://github.com/stevengj/PyPlot.jl
|
||||
|
||||
immutable PyPlotPackage <: PlottingPackage end
|
||||
|
||||
pyplot!() = plotter!(:pyplot)
|
||||
|
||||
# -------------------------------
|
||||
|
||||
|
||||
# convert colorant to 4-tuple RGBA
|
||||
getPyPlotColor(c::Colorant) = map(f->float(f(c)), (red, green, blue, alpha))
|
||||
|
||||
# get the style (solid, dashed, etc)
|
||||
function getPyPlotLineStyle(linetype::Symbol, linestyle::Symbol)
|
||||
linetype == :none && return " "
|
||||
linestyle == :solid && return "-"
|
||||
linestyle == :dash && return "--"
|
||||
linestyle == :dot && return ":"
|
||||
linestyle == :dashdot && return "-."
|
||||
linestyle == :dashdotdot && return "-."
|
||||
warn("Unknown linestyle $linestyle")
|
||||
return "-"
|
||||
end
|
||||
|
||||
# get the marker shape
|
||||
function getPyPlotMarker(marker::Symbol)
|
||||
marker == :none && return " "
|
||||
marker == :ellipse && return "o"
|
||||
marker == :rect && return "s"
|
||||
marker == :diamond && return "D"
|
||||
marker == :utriangle && return "^"
|
||||
marker == :dtriangle && return "v"
|
||||
marker == :cross && return "x"
|
||||
marker == :xcross && return "+"
|
||||
marker == :star1 && return "*"
|
||||
marker == :star2 && return "*"
|
||||
marker == :hexagon && return "h"
|
||||
warn("Unknown marker $marker")
|
||||
return "o"
|
||||
end
|
||||
|
||||
# pass through
|
||||
function getPyPlotMarker(marker::String)
|
||||
@assert length(marker) == 1
|
||||
marker
|
||||
end
|
||||
|
||||
function getPyPlotDrawStyle(linetype::Symbol)
|
||||
linetype == :step && return "steps-post"
|
||||
linetype == :stepinverted && return "steps-pre"
|
||||
return "default"
|
||||
end
|
||||
|
||||
# get a reference to the right axis
|
||||
getLeftAxis(o) = o.o[:axes][1]
|
||||
getRightAxis(o) = getLeftAxis(o)[:twinx]()
|
||||
|
||||
# left axis is PyPlot.<func>, right axis is "f.axes[0].twinx().<func>"
|
||||
function getPyPlotFunction(plt::Plot, axis::Symbol, linetype::Symbol)
|
||||
if axis == :right
|
||||
ax = getRightAxis(plt.o)
|
||||
ax[:set_ylabel](plt.initargs[:yrightlabel])
|
||||
return ax[linetype == :hist ? :hist : (linetype in (:sticks,:bar) ? :bar : (linetype in (:heatmap,:hexbin) ? :hexbin : :plot))]
|
||||
end
|
||||
return linetype == :hist ? PyPlot.plt[:hist] : (linetype in (:sticks,:bar) ? PyPlot.bar : (linetype in (:heatmap,:hexbin) ? PyPlot.hexbin : PyPlot.plot))
|
||||
end
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
# TODO:
|
||||
# fillto # might have to use barHack/histogramHack??
|
||||
# heatmap
|
||||
# subplot
|
||||
# reg # true or false, add a regression line for each line
|
||||
# pos # (Int,Int), move the enclosing window to this position
|
||||
# windowtitle # string or symbol, set the title of the enclosing windowtitle
|
||||
# screen # Integer, move enclosing window to this screen number (for multiscreen desktops)
|
||||
# show # true or false, show the plot (in case you don't want the window to pop up right away)
|
||||
|
||||
function plot(pkg::PyPlotPackage; kw...)
|
||||
# create the figure
|
||||
d = Dict(kw)
|
||||
w,h = map(px2inch, d[:size])
|
||||
bgcolor = getPyPlotColor(d[:background_color])
|
||||
o = PyPlot.figure(; figsize = (w,h), facecolor = bgcolor, dpi = 96)
|
||||
|
||||
PyPlot.title(d[:title])
|
||||
PyPlot.xlabel(d[:xlabel])
|
||||
PyPlot.ylabel(d[:ylabel])
|
||||
|
||||
plt = Plot(o, pkg, 0, d, Dict[])
|
||||
plt
|
||||
end
|
||||
|
||||
|
||||
function plot!(::PyPlotPackage, plt::Plot; kw...)
|
||||
d = Dict(kw)
|
||||
lt = d[:linetype]
|
||||
extraargs = Dict()
|
||||
|
||||
plotfunc = getPyPlotFunction(plt, d[:axis], lt)
|
||||
|
||||
# we have different args depending on plot type
|
||||
if lt in (:hist, :sticks, :bar)
|
||||
|
||||
# NOTE: this is unsupported because it does the wrong thing... it shifts the whole axis
|
||||
# extraargs[:bottom] = d[:fillto]
|
||||
|
||||
if lt == :hist
|
||||
extraargs[:bins] = d[:nbins]
|
||||
else
|
||||
extraargs[:width] = (lt == :sticks ? 0.1 : 0.9)
|
||||
end
|
||||
|
||||
elseif lt in (:heatmap, :hexbin)
|
||||
|
||||
extraargs[:gridsize] = d[:nbins]
|
||||
|
||||
else
|
||||
|
||||
# all but color/label
|
||||
extraargs[:linestyle] = getPyPlotLineStyle(lt, d[:linestyle])
|
||||
extraargs[:marker] = getPyPlotMarker(d[:marker])
|
||||
extraargs[:markersize] = d[:markersize]
|
||||
extraargs[:markerfacecolor] = getPyPlotColor(d[:markercolor])
|
||||
extraargs[:drawstyle] = getPyPlotDrawStyle(lt)
|
||||
|
||||
end
|
||||
|
||||
# set these for all types
|
||||
extraargs[:figure] = plt.o
|
||||
extraargs[:color] = getPyPlotColor(d[:color])
|
||||
extraargs[:linewidth] = d[:width]
|
||||
extraargs[:label] = d[:label]
|
||||
|
||||
# do the plot
|
||||
if lt == :hist
|
||||
d[:serieshandle] = plotfunc(d[:y]; extraargs...)
|
||||
else
|
||||
d[:serieshandle] = plotfunc(d[:x], d[:y]; extraargs...)
|
||||
end
|
||||
|
||||
# this sets the bg color inside the grid (plt.o.o == matplotlib.Figure)
|
||||
plt.o.o[:axes][1][:set_axis_bgcolor](getPyPlotColor(plt.initargs[:background_color]))
|
||||
|
||||
push!(plt.seriesargs, d)
|
||||
plt
|
||||
end
|
||||
|
||||
function addPyPlotLegend(plt::Plot)
|
||||
# add a legend?
|
||||
# try
|
||||
if plt.initargs[:legend]
|
||||
# gotta do this to ensure both axes are included
|
||||
args = filter(x -> !(x[:linetype] in (:hist,:hexbin,:heatmap)), plt.seriesargs)
|
||||
if length(args) > 0
|
||||
PyPlot.legend([d[:serieshandle][1] for d in args], [d[:label] for d in args], loc="best")
|
||||
end
|
||||
end
|
||||
# catch ex
|
||||
# warn("Error adding PyPlot legend: ", ex)
|
||||
# end
|
||||
end
|
||||
|
||||
function Base.display(::PyPlotPackage, plt::Plot)
|
||||
addPyPlotLegend(plt)
|
||||
display(plt.o)
|
||||
end
|
||||
|
||||
# -------------------------------
|
||||
|
||||
function savepng(::PyPlotPackage, plt::PlottingObject, fn::String, args...)
|
||||
addPyPlotLegend(plt)
|
||||
f = open(fn, "w")
|
||||
writemime(f, "image/png", plt.o)
|
||||
close(f)
|
||||
end
|
||||
|
||||
# -------------------------------
|
||||
|
||||
# create the underlying object (each backend will do this differently)
|
||||
function buildSubplotObject!(::PyPlotPackage, subplt::Subplot)
|
||||
# i = 0
|
||||
# rows = []
|
||||
# for rowcnt in subplt.layout.rowcounts
|
||||
# push!(rows, Qwt.hsplitter([plt.o for plt in subplt.plts[(1:rowcnt) + i]]...))
|
||||
# i += rowcnt
|
||||
# end
|
||||
# subplt.o = Qwt.vsplitter(rows...)
|
||||
error("unsupported")
|
||||
end
|
||||
|
||||
|
||||
function Base.display(::PyPlotPackage, subplt::Subplot)
|
||||
# for plt in subplt.plts
|
||||
# Qwt.refresh(plt.o)
|
||||
# end
|
||||
# Qwt.showwidget(subplt.o)
|
||||
display(subplt.o)
|
||||
end
|
||||
|
||||
@@ -25,16 +25,16 @@ function adjustQwtKeywords(iscreating::Bool; kw...)
|
||||
end
|
||||
|
||||
function plot(pkg::QwtPackage; kw...)
|
||||
kw = adjustQwtKeywords(true; kw...)
|
||||
o = Qwt.plot(zeros(0,0); kw..., show=false)
|
||||
plt = Plot(o, pkg, 0, kw, Dict[])
|
||||
d = adjustQwtKeywords(true; kw...)
|
||||
o = Qwt.plot(zeros(0,0); d..., show=false)
|
||||
plt = Plot(o, pkg, 0, d, Dict[])
|
||||
plt
|
||||
end
|
||||
|
||||
function plot!(::QwtPackage, plt::Plot; kw...)
|
||||
kw = adjustQwtKeywords(false; kw...)
|
||||
Qwt.oplot(plt.o; kw...)
|
||||
push!(plt.seriesargs, kw)
|
||||
d = adjustQwtKeywords(false; kw...)
|
||||
Qwt.oplot(plt.o; d...)
|
||||
push!(plt.seriesargs, d)
|
||||
plt
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
|
||||
# TODO: find/replace all [PkgName] with CamelCase, all [pkgname] with lowercase
|
||||
|
||||
# [WEBSITE]
|
||||
|
||||
immutable [PkgName]Package <: PlottingPackage end
|
||||
|
||||
[pkgname]!() = plotter!(:[pkgname])
|
||||
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
function plot(pkg::[PkgName]Package; kw...)
|
||||
d = Dict(kw)
|
||||
# TODO: create the window/canvas/context that is the plot within the backend (call it `o`)
|
||||
# TODO: initialize the plot... title, xlabel, bgcolor, etc
|
||||
Plot(o, pkg, 0, d, Dict[])
|
||||
end
|
||||
|
||||
|
||||
function plot!(::[PkgName]Package, plt::Plot; kw...)
|
||||
d = Dict(kw)
|
||||
# TODO: add one series to the underlying package
|
||||
push!(plt.seriesargs, d)
|
||||
plt
|
||||
end
|
||||
|
||||
|
||||
function Base.display(::[PkgName]Package, plt::Plot)
|
||||
# TODO: display/show the plot
|
||||
end
|
||||
|
||||
# -------------------------------
|
||||
|
||||
function savepng(::[PkgName]Package, plt::PlottingObject, fn::String; kw...)
|
||||
# TODO: save a PNG of the underlying plot/subplot object
|
||||
end
|
||||
|
||||
|
||||
# -------------------------------
|
||||
|
||||
function buildSubplotObject!(::[PkgName]Package, subplt::Subplot)
|
||||
# TODO: build the underlying Subplot object. this is where you might layout the panes within a GUI window, for example
|
||||
end
|
||||
|
||||
|
||||
function Base.display(::[PkgName]Package, subplt::Subplot)
|
||||
# TODO: display/show the Subplot object
|
||||
end
|
||||
@@ -112,11 +112,12 @@ function plot!(plt::Plot, args...; kw...)
|
||||
|
||||
currentPlot!(plt)
|
||||
|
||||
# do we want to show it?
|
||||
d = Dict(kw)
|
||||
if haskey(d, :show) && d[:show]
|
||||
display(plt)
|
||||
end
|
||||
# NOTE: lets ignore the show param and effectively use the semicolon at the end of the REPL statement
|
||||
# # do we want to show it?
|
||||
# d = Dict(kw)
|
||||
# if haskey(d, :show) && d[:show]
|
||||
# display(plt)
|
||||
# end
|
||||
|
||||
plt
|
||||
end
|
||||
|
||||