working on winston and examples
166
docs/winston_examples.md
Normal file
@ -0,0 +1,166 @@
|
|||||||
|
# Examples for backend: winston
|
||||||
|
|
||||||
|
- Supported arguments: `args`, `axis`, `color`, `kwargs`, `label`, `legend`, `linestyle`, `linetype`, `marker`, `markersize`, `nbins`, `reg`, `size`, `title`, `width`, `windowtitle`, `xlabel`, `ylabel`, `yrightlabel`
|
||||||
|
- Supported values for axis: `:auto`, `:left`
|
||||||
|
- Supported values for linetype: `:none`, `:line`, `:sticks`, `:scatter`, `:hist`, `:bar`
|
||||||
|
- Supported values for linestyle: `:auto`, `:solid`, `:dashdotdot`, `:dot`, `:dash`, `:dashdot`
|
||||||
|
- Supported values for marker: `:auto`, `:hexagon`, `:none`, `:dtriangle`, `:ellipse`, `:xcross`, `:rect`, `:star1`, `:star2`, `:cross`, `:utriangle`, `:diamond`
|
||||||
|
- Is `subplot`/`subplot!` supported? No
|
||||||
|
|
||||||
|
### Initialize
|
||||||
|
|
||||||
|
```julia
|
||||||
|
using Plots
|
||||||
|
winston!()
|
||||||
|
```
|
||||||
|
|
||||||
|
### Lines
|
||||||
|
|
||||||
|
A simple line plot of the 3 columns.
|
||||||
|
|
||||||
|
```julia
|
||||||
|
plot(rand(100,3))
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Functions
|
||||||
|
|
||||||
|
Plot multiple functions. You can also put the function first.
|
||||||
|
|
||||||
|
```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 (i.e. plot: (fx(u), fy(u))) 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: Currently only supported with Qwt and PyPlot
|
||||||
|
|
||||||
|
```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)
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Suported line types
|
||||||
|
|
||||||
|
All options: (:line, :orderedline, :step, :stepinverted, :sticks, :scatter, :none, :heatmap, :hexbin, :hist, :bar)
|
||||||
|
|
||||||
|
```julia
|
||||||
|
types = intersect(supportedTypes(),[:line,:step,:stepinverted,:sticks,:scatter])
|
||||||
|
n = length(types)
|
||||||
|
x = Vector[sort(rand(20)) for i = 1:n]
|
||||||
|
y = rand(20,n)
|
||||||
|
plot(x,y; linetypes=types,labels=map(string,types))
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Supported line styles
|
||||||
|
|
||||||
|
All options: (:solid, :dash, :dot, :dashdot, :dashdotdot)
|
||||||
|
|
||||||
|
```julia
|
||||||
|
styles = setdiff(supportedStyles(),[:auto])
|
||||||
|
plot(rand(20,length(styles)); linestyle=:auto,labels=map(string,styles))
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Supported marker types
|
||||||
|
|
||||||
|
All options: (:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon)
|
||||||
|
|
||||||
|
```julia
|
||||||
|
markers = setdiff(supportedMarkers(),[:none,:auto])
|
||||||
|
plot([fill(i,10) for i = 1:length(markers)]; marker=:auto,labels=map(string,markers),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)
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
BIN
img/winston/winston_example_1.png
Normal file
|
After Width: | Height: | Size: 38 KiB |
BIN
img/winston/winston_example_11.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
img/winston/winston_example_12.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
img/winston/winston_example_13.png
Normal file
|
After Width: | Height: | Size: 29 KiB |
BIN
img/winston/winston_example_14.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
img/winston/winston_example_15.png
Normal file
|
After Width: | Height: | Size: 7.8 KiB |
BIN
img/winston/winston_example_2.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
img/winston/winston_example_3.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
img/winston/winston_example_4.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
img/winston/winston_example_5.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
img/winston/winston_example_6.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
img/winston/winston_example_7.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
img/winston/winston_example_8.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
img/winston/winston_example_9.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
@ -32,7 +32,7 @@ const winston_marker = Dict(:none=>".",
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
supportedArgs(::WinstonPackage) = ARGS
|
supportedArgs(::WinstonPackage) = setdiff(ARGS, [:heatmap_c, :fillto, :pos, :markercolor, :background_color])
|
||||||
supportedAxes(::WinstonPackage) = [:auto, :left]
|
supportedAxes(::WinstonPackage) = [:auto, :left]
|
||||||
supportedTypes(::WinstonPackage) = [:none, :line, :sticks, :scatter, :hist, :bar]
|
supportedTypes(::WinstonPackage) = [:none, :line, :sticks, :scatter, :hist, :bar]
|
||||||
supportedStyles(::WinstonPackage) = unshift!(collect(keys(winston_linestyle)), :auto) # vcat(:auto, keys(winston_linestyle))
|
supportedStyles(::WinstonPackage) = unshift!(collect(keys(winston_linestyle)), :auto) # vcat(:auto, keys(winston_linestyle))
|
||||||
@ -60,14 +60,19 @@ function plot(pkg::WinstonPackage; kw...)
|
|||||||
# the call to figure does a few things here:
|
# the call to figure does a few things here:
|
||||||
# get a new unique id
|
# get a new unique id
|
||||||
# create a new GtkWindow (or Tk?)
|
# create a new GtkWindow (or Tk?)
|
||||||
w,h = d[:size]
|
|
||||||
figidx = Winston.figure(; name = d[:windowtitle], width = w, height = h)
|
|
||||||
|
|
||||||
# skip the current fig stuff... just grab the fig directly
|
# w,h = d[:size]
|
||||||
fig = Winston._display.figs[figidx]
|
# canvas = Gtk.GtkCanvasLeaf()
|
||||||
|
# window = Gtk.GtkWindowLeaf(canvas, d[:windowtitle], w, h)
|
||||||
|
|
||||||
|
# figidx = Winston.figure(; name = d[:windowtitle], width = w, height = h)
|
||||||
|
|
||||||
|
# # skip the current fig stuff... just grab the fig directly
|
||||||
|
# fig = Winston._display.figs[figidx]
|
||||||
|
|
||||||
# overwrite the placeholder FramedPlot with our own
|
# overwrite the placeholder FramedPlot with our own
|
||||||
fig.plot = Winston.FramedPlot(title = d[:title], xlabel = d[:xlabel], ylabel = d[:ylabel])
|
# fig.plot = Winston.FramedPlot(title = d[:title], xlabel = d[:xlabel], ylabel = d[:ylabel])
|
||||||
|
wplt = Winston.FramedPlot(title = d[:title], xlabel = d[:xlabel], ylabel = d[:ylabel])
|
||||||
|
|
||||||
# # using the figure index returned from Winston.figure, make this plot current and get the
|
# # using the figure index returned from Winston.figure, make this plot current and get the
|
||||||
# # Figure object (fields: window::GtkWindow and plot::FramedPlot)
|
# # Figure object (fields: window::GtkWindow and plot::FramedPlot)
|
||||||
@ -81,22 +86,36 @@ function plot(pkg::WinstonPackage; kw...)
|
|||||||
# Winston.setattr(fig.plot, "ylabel", d[:ylabel])
|
# Winston.setattr(fig.plot, "ylabel", d[:ylabel])
|
||||||
# Winston.setattr(fig.plot, "title", d[:title])
|
# Winston.setattr(fig.plot, "title", d[:title])
|
||||||
|
|
||||||
Plot((fig, figidx), pkg, 0, d, Dict[])
|
Plot(wplt, pkg, 0, d, Dict[])
|
||||||
|
# Plot((window, canvas, wplt), pkg, 0, d, Dict[])
|
||||||
|
# Plot((fig, figidx), pkg, 0, d, Dict[])
|
||||||
end
|
end
|
||||||
|
|
||||||
copy_remove(d::Dict, s::Symbol) = delete!(copy(d), s)
|
copy_remove(d::Dict, s::Symbol) = delete!(copy(d), s)
|
||||||
|
|
||||||
function addRegressionLineWinston(d::Dict)
|
function addRegressionLineWinston(d::Dict, wplt)
|
||||||
xs, ys = regressionXY(d[:x], d[:y])
|
xs, ys = regressionXY(d[:x], d[:y])
|
||||||
Winston.add(plt.o.plot, Winston.Curve(xs, ys, kind="dotted"))
|
Winston.add(wplt, Winston.Curve(xs, ys, kind="dotted"))
|
||||||
|
end
|
||||||
|
|
||||||
|
function getWinstonItems(plt::Plot)
|
||||||
|
if isa(plt.o, Winston.FramedPlot)
|
||||||
|
wplt = plt.o
|
||||||
|
window, canvas = nothing, nothing
|
||||||
|
else
|
||||||
|
window, canvas, wplt = plt.o
|
||||||
|
end
|
||||||
|
window, canvas, wplt
|
||||||
end
|
end
|
||||||
|
|
||||||
function plot!(::WinstonPackage, plt::Plot; kw...)
|
function plot!(::WinstonPackage, plt::Plot; kw...)
|
||||||
d = Dict(kw)
|
d = Dict(kw)
|
||||||
|
|
||||||
# make this figure current
|
# # make this figure current
|
||||||
fig, figidx = plt.o
|
# fig, figidx = plt.o
|
||||||
Winston.switchfig(Winston._display, figidx)
|
# Winston.switchfig(Winston._display, figidx)
|
||||||
|
|
||||||
|
window, canvas, wplt = getWinstonItems(plt)
|
||||||
|
|
||||||
# until we call it normally, do the hack
|
# until we call it normally, do the hack
|
||||||
if d[:linetype] == :bar
|
if d[:linetype] == :bar
|
||||||
@ -106,27 +125,24 @@ function plot!(::WinstonPackage, plt::Plot; kw...)
|
|||||||
|
|
||||||
e = Dict()
|
e = Dict()
|
||||||
e[:color] = d[:color]
|
e[:color] = d[:color]
|
||||||
# label # string or symbol, applies to that line, may go in a legend
|
|
||||||
e[:linewidth] = d[:width]
|
e[:linewidth] = d[:width]
|
||||||
e[:kind] = winston_linestyle[d[:linestyle]]
|
e[:kind] = winston_linestyle[d[:linestyle]]
|
||||||
e[:symbolkind] = winston_marker[d[:marker]]
|
e[:symbolkind] = winston_marker[d[:marker]]
|
||||||
# markercolor # same choices as `color`, or :match will set the color to be the same as `color`
|
# markercolor # same choices as `color`, or :match will set the color to be the same as `color`
|
||||||
e[:symbolsize] = d[:markersize] / 3
|
e[:symbolsize] = d[:markersize] / 5
|
||||||
# fillto # fillto value for area plots
|
# fillto # fillto value for area plots
|
||||||
|
|
||||||
# size # (Int,Int), resize the enclosing window
|
|
||||||
# pos # (Int,Int), move the enclosing window to this position
|
# 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)
|
# screen # Integer, move enclosing window to this screen number (for multiscreen desktops)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## lintype :line, :step, :stepinverted, :sticks, :dots, :none, :heatmap, :hexbin, :hist, :bar
|
## lintype :line, :step, :stepinverted, :sticks, :dots, :none, :heatmap, :hexbin, :hist, :bar
|
||||||
if d[:linetype] == :none
|
if d[:linetype] == :none
|
||||||
Winston.add(fig.plot, Winston.Points(d[:x], d[:y]; copy_remove(e, :kind)...))
|
Winston.add(wplt, Winston.Points(d[:x], d[:y]; copy_remove(e, :kind)...))
|
||||||
|
|
||||||
elseif d[:linetype] == :line
|
elseif d[:linetype] == :line
|
||||||
Winston.add(fig.plot, Winston.Curve(d[:x], d[:y]; e...))
|
Winston.add(wplt, Winston.Curve(d[:x], d[:y]; e...))
|
||||||
|
|
||||||
elseif d[:linetype] == :scatter
|
elseif d[:linetype] == :scatter
|
||||||
if d[:marker] == :none
|
if d[:marker] == :none
|
||||||
@ -140,7 +156,7 @@ function plot!(::WinstonPackage, plt::Plot; kw...)
|
|||||||
# fn = Winston.XXX
|
# fn = Winston.XXX
|
||||||
|
|
||||||
elseif d[:linetype] == :sticks
|
elseif d[:linetype] == :sticks
|
||||||
Winston.add(fig.plot, Winston.Stems(d[:x], d[:y]; e...))
|
Winston.add(wplt, Winston.Stems(d[:x], d[:y]; e...))
|
||||||
|
|
||||||
# elseif d[:linetype] == :dots
|
# elseif d[:linetype] == :dots
|
||||||
# fn = Winston.XXX
|
# fn = Winston.XXX
|
||||||
@ -153,7 +169,7 @@ function plot!(::WinstonPackage, plt::Plot; kw...)
|
|||||||
|
|
||||||
elseif d[:linetype] == :hist
|
elseif d[:linetype] == :hist
|
||||||
hst = hist(d[:y], d[:nbins])
|
hst = hist(d[:y], d[:nbins])
|
||||||
Winston.add(fig.plot, Winston.Histogram(hst...; copy_remove(e, :nbins)...))
|
Winston.add(wplt, Winston.Histogram(hst...; copy_remove(e, :nbins)...))
|
||||||
|
|
||||||
# elseif d[:linetype] == :bar
|
# elseif d[:linetype] == :bar
|
||||||
# # fn = Winston.XXX
|
# # fn = Winston.XXX
|
||||||
@ -166,28 +182,48 @@ function plot!(::WinstonPackage, plt::Plot; kw...)
|
|||||||
|
|
||||||
# marker
|
# marker
|
||||||
if d[:marker] != :none
|
if d[:marker] != :none
|
||||||
Winston.add(fig.plot, Winston.Points(d[:x], d[:y]; copy_remove(e, :kind)...))
|
Winston.add(wplt, Winston.Points(d[:x], d[:y]; copy_remove(e, :kind)...))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# optionally add a regression line
|
# optionally add a regression line
|
||||||
d[:reg] && d[:linetype] != :hist && addRegressionLineWinston(d)
|
d[:reg] && d[:linetype] != :hist && addRegressionLineWinston(d, wplt)
|
||||||
|
|
||||||
push!(plt.seriesargs, d)
|
push!(plt.seriesargs, d)
|
||||||
println("DONE HERE ", figidx)
|
|
||||||
plt
|
plt
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function addWinstonLegend(plt::Plot, wplt)
|
||||||
|
Winston.legend(wplt, [sd[:label] for sd in plt.seriesargs])
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function Base.display(::WinstonPackage, plt::Plot)
|
function Base.display(::WinstonPackage, plt::Plot)
|
||||||
# recreate the legend
|
# recreate the legend
|
||||||
fig, figidx = plt.o
|
# fig, figidx = plt.o
|
||||||
println("before legend")
|
|
||||||
Winston.legend(fig.plot, [sd[:label] for sd in plt.seriesargs])
|
|
||||||
println("after legend")
|
|
||||||
|
|
||||||
# display the Figure
|
window, canvas, wplt = getWinstonItems(plt)
|
||||||
display(fig)
|
|
||||||
|
if window == nothing
|
||||||
|
# initialize window
|
||||||
|
w,h = plt.initargs[:size]
|
||||||
|
canvas = Gtk.GtkCanvasLeaf()
|
||||||
|
window = Gtk.GtkWindowLeaf(canvas, plt.initargs[:windowtitle], w, h)
|
||||||
|
# wplt = plt.o
|
||||||
|
plt.o = (window, canvas, wplt)
|
||||||
|
# else
|
||||||
|
# window, canvas, wplt = plt.o
|
||||||
|
end
|
||||||
|
|
||||||
|
addWinstonLegend(plt, wplt)
|
||||||
|
|
||||||
|
Winston.display(canvas, wplt)
|
||||||
|
Gtk.showall(window)
|
||||||
|
|
||||||
|
|
||||||
|
# # display the Figure
|
||||||
|
# display(fig)
|
||||||
|
|
||||||
# display(plt.o.window)
|
# display(plt.o.window)
|
||||||
|
|
||||||
@ -199,7 +235,9 @@ end
|
|||||||
|
|
||||||
function savepng(::WinstonPackage, plt::PlottingObject, fn::String; kw...)
|
function savepng(::WinstonPackage, plt::PlottingObject, fn::String; kw...)
|
||||||
f = open(fn, "w")
|
f = open(fn, "w")
|
||||||
writemime(f, "image/png", plt.o.plot)
|
window, canvas, wplt = getWinstonItems(plt)
|
||||||
|
addWinstonLegend(plt, wplt)
|
||||||
|
writemime(f, "image/png", wplt)
|
||||||
close(f)
|
close(f)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -132,8 +132,8 @@ function plotter()
|
|||||||
|
|
||||||
elseif currentBackendSymbol == :winston
|
elseif currentBackendSymbol == :winston
|
||||||
try
|
try
|
||||||
@eval import Winston
|
@eval import Winston, Gtk
|
||||||
@eval export Winston
|
@eval export Winston, Gtk
|
||||||
catch
|
catch
|
||||||
error("Couldn't import Winston. Install it with: Pkg.add(\"Winston\")")
|
error("Couldn't import Winston. Install it with: Pkg.add(\"Winston\")")
|
||||||
end
|
end
|
||||||
|
|||||||