Compare commits

...

26 Commits

Author SHA1 Message Date
Thomas Breloff 6ae0912e0e readme 2015-09-15 13:24:14 -04:00
Thomas Breloff e8062d544d readme 2015-09-15 13:18:49 -04:00
Thomas Breloff 07332aa4ac readme 2015-09-15 13:16:19 -04:00
Thomas Breloff 1e2b3559f2 gadfly marker fixes and examples 2015-09-15 13:08:04 -04:00
Thomas Breloff 8bfaa14edb added backend template 2015-09-15 10:03:56 -04:00
Thomas Breloff d4e87d3fe8 working on gadfly and immerse 2015-09-14 23:44:28 -04:00
Thomas Breloff 460348c0b6 working on gadfly and immerse 2015-09-14 23:28:47 -04:00
Thomas Breloff 264e8c735e working on gadfly markers 2015-09-14 17:27:37 -04:00
Thomas Breloff c4b04e2327 immerse final fixes and examples 2015-09-14 15:30:09 -04:00
Thomas Breloff dc1389bd1a working on immerse 2015-09-14 15:24:18 -04:00
Thomas Breloff 51e38c80d8 working on immerse 2015-09-14 15:08:25 -04:00
Thomas Breloff a33f5fabd1 working on immerse 2015-09-14 14:41:13 -04:00
Thomas Breloff e6c8344970 working on immerse 2015-09-14 13:44:58 -04:00
Thomas Breloff 2207ae6617 working on immerse 2015-09-14 12:35:24 -04:00
Thomas Breloff cdc6707ad3 pyplot bg color 2015-09-14 10:46:33 -04:00
Thomas Breloff 448fdaecbd readme 2015-09-14 00:45:55 -04:00
Thomas Breloff 4aa79aed6f readme 2015-09-14 00:45:00 -04:00
Thomas Breloff c8fcc373f8 examples and readme 2015-09-14 00:28:08 -04:00
Thomas Breloff 1410141b46 examples 2015-09-14 00:16:24 -04:00
Thomas Breloff 76efabb5f3 heatmaps, fixes 2015-09-14 00:15:51 -04:00
Thomas Breloff 36effc6dc4 working on pyplot 2015-09-13 22:20:15 -04:00
Thomas Breloff 8d5412a38f working on pyplot 2015-09-13 21:34:28 -04:00
Thomas Breloff 465b5d20b4 working on pyplot 2015-09-13 18:39:56 -04:00
Thomas Breloff 60a22b1897 working on pyplot 2015-09-13 17:02:03 -04:00
Thomas Breloff 09a685e977 gitignore 2015-09-13 16:36:32 -04:00
Thomas Breloff 31da90865c added args and kwargs to PLOT_DEFAULTS 2015-09-13 14:06:33 -04:00
104 changed files with 1067 additions and 132 deletions
+1
View File
@@ -1,3 +1,4 @@
*.jl.cov
*.jl.*.cov
*.jl.mem
.DS_Store
+30 -19
View File
@@ -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:
![gadfly_plt](img/gadfly1.png)
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
+15 -5
View File
@@ -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
+30 -8
View File
@@ -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")
```
![](../img/gadfly/gadfly_example_6.png)
@@ -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)
```
![](../img/gadfly/gadfly_example_10.png)
@@ -113,6 +113,28 @@ plot(rand(20,4); linetypes=[:line,:step,:sticks,:dots],labels=["line","step","st
![](../img/gadfly/gadfly_example_11.png)
### 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"])
```
![](../img/gadfly/gadfly_example_12.png)
### 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)
```
![](../img/gadfly/gadfly_example_13.png)
### 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))
```
![](../img/gadfly/gadfly_example_12.png)
![](../img/gadfly/gadfly_example_14.png)
### Histogram
@@ -131,7 +153,7 @@ note: fillto isn't supported on all backends
histogram(randn(1000); nbins=50,fillto=20)
```
![](../img/gadfly/gadfly_example_13.png)
![](../img/gadfly/gadfly_example_15.png)
### 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)
```
![](../img/gadfly/gadfly_example_14.png)
![](../img/gadfly/gadfly_example_16.png)
### 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)
```
![](../img/gadfly/gadfly_example_15.png)
![](../img/gadfly/gadfly_example_17.png)
###
@@ -166,5 +188,5 @@ subplot(randn(100,5); n=4)
subplot!(randn(100,3))
```
![](../img/gadfly/gadfly_example_16.png)
![](../img/gadfly/gadfly_example_18.png)
+192
View File
@@ -0,0 +1,192 @@
### Lines
A simple line plot of the 3 columns.
```julia
plot(rand(100,3))
```
![](../img/immerse/immerse_example_1.png)
### Functions
Plot multiple functions.
```julia
plot(0:0.01:4π,[sin,cos])
```
![](../img/immerse/immerse_example_2.png)
###
You can also call it with plot(f, xmin, xmax).
```julia
plot([sin,cos],0,4π)
```
![](../img/immerse/immerse_example_3.png)
###
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π)
```
![](../img/immerse/immerse_example_4.png)
### 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))
```
![](../img/immerse/immerse_example_5.png)
### 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")
```
![](../img/immerse/immerse_example_6.png)
### 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])
```
![](../img/immerse/immerse_example_7.png)
### Build plot in pieces
Start with a base plot...
```julia
plot(rand(100) / 3; reg=true,fillto=0)
```
![](../img/immerse/immerse_example_8.png)
###
and add to it later.
```julia
scatter!(rand(100); markersize=6,color=:blue)
```
![](../img/immerse/immerse_example_9.png)
### Heatmaps
```julia
heatmap(randn(10000),randn(10000); nbins=100)
```
![](../img/immerse/immerse_example_10.png)
### 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"])
```
![](../img/immerse/immerse_example_11.png)
### 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"])
```
![](../img/immerse/immerse_example_12.png)
### 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)
```
![](../img/immerse/immerse_example_13.png)
### Bar
x is the midpoint of the bar. (todo: allow passing of edges instead of midpoints)
```julia
bar(randn(1000))
```
![](../img/immerse/immerse_example_14.png)
### Histogram
note: fillto isn't supported on all backends
```julia
histogram(randn(1000); nbins=50,fillto=20)
```
![](../img/immerse/immerse_example_15.png)
### 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)
```
![](../img/immerse/immerse_example_16.png)
### 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)
```
![](../img/immerse/immerse_example_17.png)
###
```julia
subplot!(randn(100,3))
```
![](../img/immerse/immerse_example_18.png)
+157
View File
@@ -0,0 +1,157 @@
### Lines
A simple line plot of the 3 columns.
```julia
plot(rand(100,3))
```
![](../img/pyplot/pyplot_example_1.png)
### Functions
Plot multiple functions.
```julia
plot(0:0.01:4π,[sin,cos])
```
![](../img/pyplot/pyplot_example_2.png)
###
You can also call it with plot(f, xmin, xmax).
```julia
plot([sin,cos],0,4π)
```
![](../img/pyplot/pyplot_example_3.png)
###
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π)
```
![](../img/pyplot/pyplot_example_4.png)
### 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))
```
![](../img/pyplot/pyplot_example_5.png)
### 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")
```
![](../img/pyplot/pyplot_example_6.png)
### 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])
```
![](../img/pyplot/pyplot_example_7.png)
### Build plot in pieces
Start with a base plot...
```julia
plot(rand(100) / 3; reg=true,fillto=0)
```
![](../img/pyplot/pyplot_example_8.png)
###
and add to it later.
```julia
scatter!(rand(100); markersize=6,color=:blue)
```
![](../img/pyplot/pyplot_example_9.png)
### Heatmaps
```julia
heatmap(randn(10000),randn(10000); nbins=100)
```
![](../img/pyplot/pyplot_example_10.png)
### 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"])
```
![](../img/pyplot/pyplot_example_11.png)
### 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"])
```
![](../img/pyplot/pyplot_example_12.png)
### 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)
```
![](../img/pyplot/pyplot_example_13.png)
### Bar
x is the midpoint of the bar. (todo: allow passing of edges instead of midpoints)
```julia
bar(randn(1000))
```
![](../img/pyplot/pyplot_example_14.png)
### Histogram
note: fillto isn't supported on all backends
```julia
histogram(randn(1000); nbins=50,fillto=20)
```
![](../img/pyplot/pyplot_example_15.png)
+30 -8
View File
@@ -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")
```
![](../img/qwt/qwt_example_6.png)
@@ -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)
```
![](../img/qwt/qwt_example_10.png)
@@ -113,6 +113,28 @@ plot(rand(20,4); linetypes=[:line,:step,:sticks,:dots],labels=["line","step","st
![](../img/qwt/qwt_example_11.png)
### 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"])
```
![](../img/qwt/qwt_example_12.png)
### 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)
```
![](../img/qwt/qwt_example_13.png)
### 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))
```
![](../img/qwt/qwt_example_12.png)
![](../img/qwt/qwt_example_14.png)
### Histogram
@@ -131,7 +153,7 @@ note: fillto isn't supported on all backends
histogram(randn(1000); nbins=50,fillto=20)
```
![](../img/qwt/qwt_example_13.png)
![](../img/qwt/qwt_example_15.png)
### 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)
```
![](../img/qwt/qwt_example_14.png)
![](../img/qwt/qwt_example_16.png)
### 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)
```
![](../img/qwt/qwt_example_15.png)
![](../img/qwt/qwt_example_17.png)
###
@@ -166,5 +188,5 @@ subplot(randn(100,5); n=4)
subplot!(randn(100,3))
```
![](../img/qwt/qwt_example_16.png)
![](../img/qwt/qwt_example_18.png)
+28 -6
View File
@@ -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")
```
![](../img/unicodeplots/unicodeplots_example_6.png)
@@ -103,6 +103,28 @@ plot(rand(20,4); linetypes=[:line,:step,:sticks,:dots],labels=["line","step","st
![](../img/unicodeplots/unicodeplots_example_11.png)
### 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"])
```
![](../img/unicodeplots/unicodeplots_example_12.png)
### 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)
```
![](../img/unicodeplots/unicodeplots_example_13.png)
### 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))
```
![](../img/unicodeplots/unicodeplots_example_12.png)
![](../img/unicodeplots/unicodeplots_example_14.png)
### Histogram
@@ -121,7 +143,7 @@ note: fillto isn't supported on all backends
histogram(randn(1000); nbins=50,fillto=20)
```
![](../img/unicodeplots/unicodeplots_example_13.png)
![](../img/unicodeplots/unicodeplots_example_15.png)
### 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)
```
![](../img/unicodeplots/unicodeplots_example_14.png)
![](../img/unicodeplots/unicodeplots_example_16.png)
### 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)
```
![](../img/unicodeplots/unicodeplots_example_15.png)
![](../img/unicodeplots/unicodeplots_example_17.png)
###
@@ -156,5 +178,5 @@ subplot(randn(100,5); n=4)
subplot!(randn(100,3))
```
![](../img/unicodeplots/unicodeplots_example_16.png)
![](../img/unicodeplots/unicodeplots_example_18.png)
Binary file not shown.

Before

Width:  |  Height:  |  Size: 84 KiB

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 103 KiB

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 KiB

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 38 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 199 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 KiB

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.3 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.9 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.7 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 142 KiB

After

Width:  |  Height:  |  Size: 147 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 101 KiB

After

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 114 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 94 KiB

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 69 KiB

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 74 KiB

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

After

Width:  |  Height:  |  Size: 57 KiB

+4 -1
View File
@@ -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
# ---------------------------------------------------------
+24
View File
@@ -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
+111 -59
View File
@@ -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
+88
View File
@@ -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
+202
View File
@@ -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
+6 -6
View File
@@ -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
+50
View File
@@ -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
+6 -5
View File
@@ -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

Some files were not shown because too many files have changed in this diff Show More