working on pyplot
This commit is contained in:
parent
09a685e977
commit
60a22b1897
@ -123,9 +123,10 @@ end
|
||||
|
||||
# run it!
|
||||
# note: generate separately so it's easy to comment out
|
||||
generate_markdown(:qwt)
|
||||
generate_markdown(:gadfly)
|
||||
generate_markdown(:unicodeplots)
|
||||
# generate_markdown(:qwt)
|
||||
# generate_markdown(:gadfly)
|
||||
# generate_markdown(:unicodeplots)
|
||||
generate_markdown(:pyplot)
|
||||
|
||||
|
||||
end # module
|
||||
|
||||
@ -32,7 +32,8 @@ export
|
||||
backends,
|
||||
qwt!,
|
||||
gadfly!,
|
||||
unicodeplots!
|
||||
unicodeplots!,
|
||||
pyplot!
|
||||
|
||||
# ---------------------------------------------------------
|
||||
|
||||
@ -67,6 +68,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
|
||||
|
||||
|
||||
# ---------------------------------------------------------
|
||||
|
||||
73
src/backends/pyplot.jl
Normal file
73
src/backends/pyplot.jl
Normal file
@ -0,0 +1,73 @@
|
||||
|
||||
# https://github.com/tbreloff/Qwt.jl
|
||||
|
||||
immutable PyPlotPackage <: PlottingPackage end
|
||||
|
||||
pyplot!() = plotter!(:pyplot)
|
||||
|
||||
# -------------------------------
|
||||
|
||||
# function adjustQwtKeywords(iscreating::Bool; kw...)
|
||||
# d = Dict(kw)
|
||||
# d[:heatmap_n] = d[:nbins]
|
||||
|
||||
# if d[:linetype] == :hexbin
|
||||
# d[:linetype] = :heatmap
|
||||
# elseif d[:linetype] == :dots
|
||||
# d[:linetype] = :none
|
||||
# d[:marker] = :hexagon
|
||||
# elseif !iscreating && d[:linetype] == :bar
|
||||
# return barHack(; kw...)
|
||||
# elseif !iscreating && d[:linetype] == :hist
|
||||
# return barHack(; histogramHack(; kw...)...)
|
||||
# end
|
||||
# d
|
||||
# end
|
||||
|
||||
function plot(pkg::PyPlotPackage; kw...)
|
||||
# kw = adjustQwtKeywords(true; kw...)
|
||||
# o = Qwt.plot(zeros(0,0); kw..., show=false)
|
||||
plt = Plot(o, pkg, 0, kw, Dict[])
|
||||
plt
|
||||
end
|
||||
|
||||
function plot!(::PyPlotPackage, plt::Plot; kw...)
|
||||
# kw = adjustQwtKeywords(false; kw...)
|
||||
# Qwt.oplot(plt.o; kw...)
|
||||
push!(plt.seriesargs, kw)
|
||||
plt
|
||||
end
|
||||
|
||||
function Base.display(::PyPlotPackage, plt::Plot)
|
||||
# Qwt.refresh(plt.o)
|
||||
# Qwt.showwidget(plt.o)
|
||||
display(plt.o)
|
||||
end
|
||||
|
||||
# -------------------------------
|
||||
|
||||
savepng(::PyPlotPackage, plt::PlottingObject, fn::String, args...) = error("unsupported")
|
||||
|
||||
# -------------------------------
|
||||
|
||||
# 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
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
include("backends/qwt.jl")
|
||||
include("backends/gadfly.jl")
|
||||
include("backends/unicodeplots.jl")
|
||||
include("backends/pyplot.jl")
|
||||
|
||||
|
||||
|
||||
# ---------------------------------------------------------
|
||||
@ -12,40 +14,61 @@ plot(pkg::PlottingPackage; kw...) = error("plot($pkg; kw...) is not implemented"
|
||||
plot!(pkg::PlottingPackage, plt::Plot; kw...) = error("plot!($pkg, plt; kw...) is not implemented")
|
||||
Base.display(pkg::PlottingPackage, plt::Plot) = error("display($pkg, plt) is not implemented")
|
||||
|
||||
subplot(pkg::PlottingPackage; kw...) = error("subplot($pkg; kw...) is not implemented")
|
||||
subplot!(pkg::PlottingPackage, subplt::Subplot; kw...) = error("subplot!($pkg, subplt; kw...) is not implemented")
|
||||
Base.display(pkg::PlottingPackage, subplt::Subplot) = error("display($pkg, subplt) is not implemented")
|
||||
|
||||
# ---------------------------------------------------------
|
||||
|
||||
|
||||
const AVAILABLE_PACKAGES = [:qwt, :gadfly, :unicodeplots]
|
||||
const AVAILABLE_PACKAGES = [:qwt, :gadfly, :unicodeplots, :pyplot]
|
||||
const INITIALIZED_PACKAGES = Set{Symbol}()
|
||||
backends() = AVAILABLE_PACKAGES
|
||||
|
||||
|
||||
function getPlottingPackage(sym::Symbol)
|
||||
sym == :qwt && return QwtPackage()
|
||||
sym == :gadfly && return GadflyPackage()
|
||||
sym == :unicodeplots && return UnicodePlotsPackage()
|
||||
sym == :pyplot && return PyPlotPackage()
|
||||
error("Unsupported backend $sym")
|
||||
end
|
||||
|
||||
|
||||
type CurrentPackage
|
||||
sym::Symbol
|
||||
pkg::PlottingPackage
|
||||
end
|
||||
CurrentPackage(sym::Symbol) = CurrentPackage(sym, getPlottingPackage(sym))
|
||||
|
||||
# ---------------------------------------------------------
|
||||
|
||||
function pickDefaultBackend()
|
||||
try
|
||||
Pkg.installed("Qwt")
|
||||
return CurrentPackage(:qwt, QwtPackage())
|
||||
return CurrentPackage(:qwt)
|
||||
end
|
||||
try
|
||||
Pkg.installed("PyPlot")
|
||||
return CurrentPackage(:pyplot)
|
||||
end
|
||||
try
|
||||
Pkg.installed("Gadfly")
|
||||
return CurrentPackage(:gadfly, GadflyPackage())
|
||||
return CurrentPackage(:gadfly)
|
||||
end
|
||||
try
|
||||
Pkg.installed("UnicodePlots")
|
||||
return CurrentPackage(:unicodeplots, UnicodePlotsPackage())
|
||||
return CurrentPackage(:unicodeplots)
|
||||
end
|
||||
warn("You don't have any of the supported backends installed! Chose from ", backends())
|
||||
return CurrentPackage(:gadfly, GadflyPackage())
|
||||
return CurrentPackage(:gadfly)
|
||||
end
|
||||
const CURRENT_PACKAGE = pickDefaultBackend()
|
||||
println("[Plots.jl] Default backend: ", CURRENT_PACKAGE.sym)
|
||||
# const CURRENT_PACKAGE = CurrentPackage(:gadfly, GadflyPackage())
|
||||
|
||||
|
||||
# ---------------------------------------------------------
|
||||
|
||||
doc"""
|
||||
Returns the current plotting package name. Initializes package on first call.
|
||||
"""
|
||||
@ -74,6 +97,12 @@ function plotter()
|
||||
catch
|
||||
error("Couldn't import UnicodePlots. Install it with: Pkg.add(\"UnicodePlots\")")
|
||||
end
|
||||
elseif currentPackageSymbol == :pyplot
|
||||
try
|
||||
@eval import PyPlot
|
||||
catch
|
||||
error("Couldn't import PyPlot. Install it with: Pkg.add(\"PyPlot\")")
|
||||
end
|
||||
else
|
||||
error("Unknown plotter $currentPackageSymbol. Choose from: $AVAILABLE_PACKAGES")
|
||||
end
|
||||
@ -96,6 +125,8 @@ function plotter!(modname)
|
||||
CURRENT_PACKAGE.pkg = GadflyPackage()
|
||||
elseif modname == :unicodeplots
|
||||
CURRENT_PACKAGE.pkg = UnicodePlotsPackage()
|
||||
elseif modname == :pyplot
|
||||
CURRENT_PACKAGE.pkg = PyPlotPackage()
|
||||
else
|
||||
error("Unknown plotter $modname. Choose from: $AVAILABLE_PACKAGES")
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user