working on immerse
This commit is contained in:
parent
cdc6707ad3
commit
2207ae6617
@ -14,6 +14,7 @@ Please add wishlist items, bugs, or any other comments/questions to the issues l
|
|||||||
- [Gadfly.jl](docs/gadfly_examples.md)
|
- [Gadfly.jl](docs/gadfly_examples.md)
|
||||||
- [UnicodePlots.jl](docs/unicodeplots_examples.md)
|
- [UnicodePlots.jl](docs/unicodeplots_examples.md)
|
||||||
- [PyPlot.jl](docs/pyplot_examples.md)
|
- [PyPlot.jl](docs/pyplot_examples.md)
|
||||||
|
- [Immerse.jl](docs/immerse_examples.md)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@ -30,6 +31,7 @@ Pkg.add("Gadfly")
|
|||||||
Pkg.clone("https://github.com/tbreloff/Qwt.jl.git") # requires pyqt and pyqwt
|
Pkg.clone("https://github.com/tbreloff/Qwt.jl.git") # requires pyqt and pyqwt
|
||||||
Pkg.add("UnicodePlots")
|
Pkg.add("UnicodePlots")
|
||||||
Pkg.add("PyPlot") # requires python and matplotlib
|
Pkg.add("PyPlot") # requires python and matplotlib
|
||||||
|
Pkg.add("Immerse")
|
||||||
```
|
```
|
||||||
|
|
||||||
## Use
|
## Use
|
||||||
@ -206,9 +208,9 @@ xlabel = ""
|
|||||||
ylabel = ""
|
ylabel = ""
|
||||||
yrightlabel = ""
|
yrightlabel = ""
|
||||||
reg = false
|
reg = false
|
||||||
size = (800,600)
|
size = (600,400)
|
||||||
pos = (0,0)
|
pos = (0,0)
|
||||||
windowtitle = ""
|
windowtitle = "Plots.jl"
|
||||||
screen = 1
|
screen = 1
|
||||||
show = true
|
show = true
|
||||||
```
|
```
|
||||||
|
|||||||
@ -131,10 +131,11 @@ end
|
|||||||
|
|
||||||
# run it!
|
# run it!
|
||||||
# note: generate separately so it's easy to comment out
|
# note: generate separately so it's easy to comment out
|
||||||
generate_markdown(:qwt)
|
# generate_markdown(:qwt)
|
||||||
generate_markdown(:gadfly)
|
# generate_markdown(:gadfly)
|
||||||
@osx_only generate_markdown(:unicodeplots)
|
# @osx_only generate_markdown(:unicodeplots)
|
||||||
generate_markdown(:pyplot)
|
# generate_markdown(:pyplot)
|
||||||
|
generate_markdown(:immerse)
|
||||||
|
|
||||||
|
|
||||||
end # module
|
end # module
|
||||||
|
|||||||
@ -33,7 +33,8 @@ export
|
|||||||
qwt!,
|
qwt!,
|
||||||
gadfly!,
|
gadfly!,
|
||||||
unicodeplots!,
|
unicodeplots!,
|
||||||
pyplot!
|
pyplot!,
|
||||||
|
immerse!
|
||||||
|
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@ -40,6 +40,7 @@ PLOT_DEFAULTS[:legend] = true
|
|||||||
PLOT_DEFAULTS[:xticks] = true
|
PLOT_DEFAULTS[:xticks] = true
|
||||||
PLOT_DEFAULTS[:yticks] = true
|
PLOT_DEFAULTS[:yticks] = true
|
||||||
PLOT_DEFAULTS[:size] = (600,400)
|
PLOT_DEFAULTS[:size] = (600,400)
|
||||||
|
PLOT_DEFAULTS[:windowtitle] = "Plots.jl"
|
||||||
|
|
||||||
PLOT_DEFAULTS[:args] = [] # additional args to pass to the backend
|
PLOT_DEFAULTS[:args] = [] # additional args to pass to the backend
|
||||||
PLOT_DEFAULTS[:kwargs] = [] # additional keyword args to pass to the backend
|
PLOT_DEFAULTS[:kwargs] = [] # additional keyword args to pass to the backend
|
||||||
|
|||||||
@ -6,32 +6,56 @@ immutable GadflyPackage <: PlottingPackage end
|
|||||||
gadfly!() = plotter!(:gadfly)
|
gadfly!() = plotter!(:gadfly)
|
||||||
|
|
||||||
|
|
||||||
# create a blank Gadfly.Plot object
|
# # create a blank Gadfly.Plot object
|
||||||
function plot(pkg::GadflyPackage; kw...)
|
# function plot(pkg::GadflyPackage; kw...)
|
||||||
|
# @eval import DataFrames
|
||||||
|
|
||||||
|
# plt = Gadfly.Plot()
|
||||||
|
# plt.mapping = Dict()
|
||||||
|
# plt.data_source = DataFrames.DataFrame()
|
||||||
|
# plt.layers = plt.layers[1:0]
|
||||||
|
|
||||||
|
# # add the title, axis labels, and theme
|
||||||
|
# d = Dict(kw)
|
||||||
|
|
||||||
|
# plt.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[]))
|
||||||
|
# end
|
||||||
|
|
||||||
|
# plt.theme = Gadfly.Theme(background_color = (haskey(d, :background_color) ? d[:background_color] : colorant"white"))
|
||||||
|
|
||||||
|
# Plot(plt, pkg, 0, d, Dict[])
|
||||||
|
# end
|
||||||
|
|
||||||
|
function createGadflyPlotObject(d::Dict)
|
||||||
@eval import DataFrames
|
@eval import DataFrames
|
||||||
|
|
||||||
plt = Gadfly.Plot()
|
gplt = Gadfly.Plot()
|
||||||
plt.mapping = Dict()
|
gplt.mapping = Dict()
|
||||||
plt.data_source = DataFrames.DataFrame()
|
gplt.data_source = DataFrames.DataFrame()
|
||||||
plt.layers = plt.layers[1:0]
|
gplt.layers = gplt.layers[1:0]
|
||||||
|
|
||||||
# add the title, axis labels, and theme
|
# 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.ylabel(d[:ylabel]),
|
||||||
Gadfly.Guide.title(d[:title])]
|
Gadfly.Guide.title(d[:title])]
|
||||||
|
|
||||||
# add the legend?
|
# add the legend?
|
||||||
if d[: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
|
end
|
||||||
|
|
||||||
plt.theme = Gadfly.Theme(background_color = (haskey(d, :background_color) ? d[:background_color] : colorant"white"))
|
gplt.theme = Gadfly.Theme(background_color = (haskey(d, :background_color) ? d[:background_color] : colorant"white"))
|
||||||
|
gplt
|
||||||
Plot(plt, pkg, 0, d, Dict[])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function getGeomFromLineType(linetype::Symbol, nbins::Int)
|
function getGeomFromLineType(linetype::Symbol, nbins::Int)
|
||||||
linetype == :line && return Gadfly.Geom.line
|
linetype == :line && return Gadfly.Geom.line
|
||||||
linetype == :dots && return Gadfly.Geom.point
|
linetype == :dots && return Gadfly.Geom.point
|
||||||
@ -64,10 +88,7 @@ function getGeoms(linetype::Symbol, marker::Symbol, nbins::Int)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# plot one data series
|
function addGadflySeries!(gplt, d::Dict)
|
||||||
function plot!(::GadflyPackage, plt::Plot; kw...)
|
|
||||||
d = Dict(kw)
|
|
||||||
|
|
||||||
gfargs = []
|
gfargs = []
|
||||||
|
|
||||||
# add the Geoms
|
# add the Geoms
|
||||||
@ -88,23 +109,80 @@ function plot!(::GadflyPackage, plt::Plot; kw...)
|
|||||||
x = d[d[:linetype] == :hist ? :y : :x]
|
x = d[d[:linetype] == :hist ? :y : :x]
|
||||||
|
|
||||||
# add to the legend
|
# add to the legend
|
||||||
if length(plt.o.guides) > 0 && isa(plt.o.guides[1], Gadfly.Guide.ManualColorKey)
|
if length(gplt.guides) > 0 && isa(gplt.guides[1], Gadfly.Guide.ManualColorKey)
|
||||||
push!(plt.o.guides[1].labels, d[:label])
|
push!(gplt.guides[1].labels, d[:label])
|
||||||
push!(plt.o.guides[1].colors, d[:color])
|
push!(gplt.guides[1].colors, d[:color])
|
||||||
end
|
end
|
||||||
|
|
||||||
if d[:axis] != :left
|
if d[:axis] != :left
|
||||||
warn("Gadly only supports one y axis")
|
warn("Gadly only supports one y axis")
|
||||||
end
|
end
|
||||||
|
|
||||||
# save the kw args
|
|
||||||
push!(plt.seriesargs, d)
|
|
||||||
|
|
||||||
# add the layer to the Gadfly.Plot
|
# add the layer to the Gadfly.Plot
|
||||||
prepend!(plt.o.layers, Gadfly.layer(unique(gfargs)..., d[:args]...; x = x, y = d[:y], d[:kwargs]...))
|
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
|
plt
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# # plot one data series
|
||||||
|
# function plot!(::GadflyPackage, plt::Plot; kw...)
|
||||||
|
# d = Dict(kw)
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
# # add a regression line?
|
||||||
|
# if d[:reg]
|
||||||
|
# push!(gfargs, Gadfly.Geom.smooth(method=:lm))
|
||||||
|
# end
|
||||||
|
|
||||||
|
# # 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)..., d[:args]...; x = x, y = d[:y], d[:kwargs]...))
|
||||||
|
# plt
|
||||||
|
# end
|
||||||
|
|
||||||
function Base.display(::GadflyPackage, plt::Plot)
|
function Base.display(::GadflyPackage, plt::Plot)
|
||||||
display(plt.o)
|
display(plt.o)
|
||||||
end
|
end
|
||||||
|
|||||||
68
src/backends/immerse.jl
Normal file
68
src/backends/immerse.jl
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
|
||||||
|
# https://github.com/JuliaGraphics/Immerse.jl
|
||||||
|
|
||||||
|
immutable ImmersePackage <: PlottingPackage end
|
||||||
|
|
||||||
|
immerse!() = plotter!(:immerse)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# create a blank Gadfly.Plot object
|
||||||
|
function plot(pkg::ImmersePackage; kw...)
|
||||||
|
d = Dict(kw)
|
||||||
|
|
||||||
|
# create the underlying Gadfly.Plot object
|
||||||
|
gplt = createGadflyPlotObject(d)
|
||||||
|
|
||||||
|
# create the figure. Immerse just returns the index of the Figure in the GadflyDisplay... call Figure(figidx) to get the object
|
||||||
|
w,h = d[:size]
|
||||||
|
figidx = Immerse.figure(; name = d[:windowtitle], width = w, height = h)
|
||||||
|
fig = Immerse.Figure(figidx)
|
||||||
|
|
||||||
|
# save both the Immerse.Figure and the Gadfly.Plot
|
||||||
|
Plot((fig,gplt), pkg, 0, d, Dict[])
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# plot one data series
|
||||||
|
function plot!(::ImmersePackage, plt::Plot; kw...)
|
||||||
|
d = Dict(kw)
|
||||||
|
addGadflySeries!(plt.o[2], d)
|
||||||
|
push!(plt.seriesargs, d)
|
||||||
|
plt
|
||||||
|
end
|
||||||
|
|
||||||
|
function Base.display(::ImmersePackage, plt::Plot)
|
||||||
|
display(plt.o[2])
|
||||||
|
end
|
||||||
|
|
||||||
|
# -------------------------------
|
||||||
|
|
||||||
|
function savepng(::ImmersePackage, plt::PlottingObject, fn::String;
|
||||||
|
w = 6 * Immerse.inch,
|
||||||
|
h = 4 * Immerse.inch)
|
||||||
|
Immerse.draw(Immerse.PNG(fn, w, h), plt.o)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# -------------------------------
|
||||||
|
|
||||||
|
# create the underlying object (each backend will do this differently)
|
||||||
|
function buildSubplotObject!(::ImmersePackage, subplt::Subplot)
|
||||||
|
i = 0
|
||||||
|
rows = []
|
||||||
|
for rowcnt in subplt.layout.rowcounts
|
||||||
|
push!(rows, Gadfly.hstack([plt.o[2] for plt in subplt.plts[(1:rowcnt) + i]]...))
|
||||||
|
i += rowcnt
|
||||||
|
end
|
||||||
|
gctx = Gadfly.vstack(rows...)
|
||||||
|
|
||||||
|
figidx = Immerse.figure()
|
||||||
|
fig = Immerse.Figure(figidx)
|
||||||
|
(fig, gctx)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function Base.display(::ImmersePackage, subplt::Subplot)
|
||||||
|
display(subplt.o[2])
|
||||||
|
end
|
||||||
@ -4,7 +4,7 @@ include("backends/qwt.jl")
|
|||||||
include("backends/gadfly.jl")
|
include("backends/gadfly.jl")
|
||||||
include("backends/unicodeplots.jl")
|
include("backends/unicodeplots.jl")
|
||||||
include("backends/pyplot.jl")
|
include("backends/pyplot.jl")
|
||||||
|
include("backends/immerse.jl")
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
@ -21,7 +21,7 @@ Base.display(pkg::PlottingPackage, subplt::Subplot) = error("display($pkg, subpl
|
|||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
const AVAILABLE_PACKAGES = [:qwt, :gadfly, :unicodeplots, :pyplot]
|
const AVAILABLE_PACKAGES = [:qwt, :gadfly, :unicodeplots, :pyplot, :immerse]
|
||||||
const INITIALIZED_PACKAGES = Set{Symbol}()
|
const INITIALIZED_PACKAGES = Set{Symbol}()
|
||||||
backends() = AVAILABLE_PACKAGES
|
backends() = AVAILABLE_PACKAGES
|
||||||
|
|
||||||
@ -31,6 +31,7 @@ function getPlottingPackage(sym::Symbol)
|
|||||||
sym == :gadfly && return GadflyPackage()
|
sym == :gadfly && return GadflyPackage()
|
||||||
sym == :unicodeplots && return UnicodePlotsPackage()
|
sym == :unicodeplots && return UnicodePlotsPackage()
|
||||||
sym == :pyplot && return PyPlotPackage()
|
sym == :pyplot && return PyPlotPackage()
|
||||||
|
sym == :immerse && return ImmersePackage()
|
||||||
error("Unsupported backend $sym")
|
error("Unsupported backend $sym")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -44,6 +45,10 @@ CurrentPackage(sym::Symbol) = CurrentPackage(sym, getPlottingPackage(sym))
|
|||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
function pickDefaultBackend()
|
function pickDefaultBackend()
|
||||||
|
try
|
||||||
|
Pkg.installed("Immerse")
|
||||||
|
return CurrentPackage(:immerse)
|
||||||
|
end
|
||||||
try
|
try
|
||||||
Pkg.installed("Qwt")
|
Pkg.installed("Qwt")
|
||||||
return CurrentPackage(:qwt)
|
return CurrentPackage(:qwt)
|
||||||
@ -85,24 +90,36 @@ function plotter()
|
|||||||
catch
|
catch
|
||||||
error("Couldn't import Qwt. Install it with: Pkg.clone(\"https://github.com/tbreloff/Qwt.jl.git\")\n (Note: also requires pyqt and pyqwt)")
|
error("Couldn't import Qwt. Install it with: Pkg.clone(\"https://github.com/tbreloff/Qwt.jl.git\")\n (Note: also requires pyqt and pyqwt)")
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif currentPackageSymbol == :gadfly
|
elseif currentPackageSymbol == :gadfly
|
||||||
try
|
try
|
||||||
@eval import Gadfly
|
@eval import Gadfly
|
||||||
catch
|
catch
|
||||||
error("Couldn't import Gadfly. Install it with: Pkg.add(\"Gadfly\")")
|
error("Couldn't import Gadfly. Install it with: Pkg.add(\"Gadfly\")")
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif currentPackageSymbol == :unicodeplots
|
elseif currentPackageSymbol == :unicodeplots
|
||||||
try
|
try
|
||||||
@eval import UnicodePlots
|
@eval import UnicodePlots
|
||||||
catch
|
catch
|
||||||
error("Couldn't import UnicodePlots. Install it with: Pkg.add(\"UnicodePlots\")")
|
error("Couldn't import UnicodePlots. Install it with: Pkg.add(\"UnicodePlots\")")
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif currentPackageSymbol == :pyplot
|
elseif currentPackageSymbol == :pyplot
|
||||||
try
|
try
|
||||||
@eval import PyPlot
|
@eval import PyPlot
|
||||||
catch
|
catch
|
||||||
error("Couldn't import PyPlot. Install it with: Pkg.add(\"PyPlot\")")
|
error("Couldn't import PyPlot. Install it with: Pkg.add(\"PyPlot\")")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
elseif currentPackageSymbol == :immerse
|
||||||
|
try
|
||||||
|
@eval import Immerse
|
||||||
|
@eval import Gadfly
|
||||||
|
catch
|
||||||
|
error("Couldn't import Immerse. Install it with: Pkg.add(\"Immerse\")")
|
||||||
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
error("Unknown plotter $currentPackageSymbol. Choose from: $AVAILABLE_PACKAGES")
|
error("Unknown plotter $currentPackageSymbol. Choose from: $AVAILABLE_PACKAGES")
|
||||||
end
|
end
|
||||||
@ -127,6 +144,8 @@ function plotter!(modname)
|
|||||||
CURRENT_PACKAGE.pkg = UnicodePlotsPackage()
|
CURRENT_PACKAGE.pkg = UnicodePlotsPackage()
|
||||||
elseif modname == :pyplot
|
elseif modname == :pyplot
|
||||||
CURRENT_PACKAGE.pkg = PyPlotPackage()
|
CURRENT_PACKAGE.pkg = PyPlotPackage()
|
||||||
|
elseif modname == :immerse
|
||||||
|
CURRENT_PACKAGE.pkg = ImmersePackage()
|
||||||
else
|
else
|
||||||
error("Unknown plotter $modname. Choose from: $AVAILABLE_PACKAGES")
|
error("Unknown plotter $modname. Choose from: $AVAILABLE_PACKAGES")
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user