pdf/ps/svg outputs

This commit is contained in:
Thomas Breloff 2015-10-19 14:11:22 -04:00
parent dcd50a7c62
commit 8208f6947f
13 changed files with 809 additions and 396 deletions

View File

@ -29,6 +29,8 @@ Please add wishlist items, bugs, or any other comments/questions to the issues l
- [Qwt.jl](docs/qwt_examples.md)
- [Winston.jl](docs/winston_examples.md)
Also check out the many [IJulia notebooks](http://nbviewer.ipython.org/github/tbreloff/Plots.jl/tree/master/examples/) with many examples.
## Installation
First, add the package
@ -84,9 +86,6 @@ png("gadfly1")
![gadfly_plt](img/gadfly1.png)
See the examples pages for lots of examples of plots, and what those commands produce for each supported backend.
Also check out the [IJulia notebooks](examples) and see how it works interactively.
## API
Call `backend(backend::Symbol)` or the shorthands (`gadfly()`, `qwt()`, `unicodeplots()`, etc) to set the current plotting backend.

View File

@ -110,6 +110,7 @@ include("plot.jl")
include("subplot.jl")
include("recipes.jl")
include("animation.jl")
include("output.jl")
# ---------------------------------------------------------
@ -173,79 +174,6 @@ xaxis!(plt::Plot, args...; kw...) = plot!(pl
yaxis!(plt::Plot, args...; kw...) = plot!(plt; yaxis = args, kw...)
# ---------------------------------------------------------
defaultOutputFormat(plt::PlottingObject) = "png"
function png(plt::PlottingObject, fn::@compat(AbstractString))
fn = addExtension(fn, "png")
io = open(fn, "w")
writemime(io, MIME("image/png"), plt)
close(io)
end
png(fn::@compat(AbstractString)) = png(current(), fn)
@compat const _savemap = Dict(
"png" => png,
)
function getExtension(fn::@compat(AbstractString))
pieces = split(fn, ".")
length(pieces) > 1 || error("Can't extract file extension: ", fn)
ext = pieces[end]
haskey(_savemap, ext) || error("Invalid file extension: ", fn)
ext
end
function addExtension(fn::@compat(AbstractString), ext::@compat(AbstractString))
try
oldext = getExtension(fn)
if oldext == ext
return fn
else
return "$fn.$ext"
end
catch
return "$fn.$ext"
end
end
function savefig(plt::PlottingObject, fn::@compat(AbstractString))
# get the extension
local ext
try
ext = getExtension(fn)
catch
# if we couldn't extract the extension, add the default
ext = defaultOutputFormat(plt)
fn = addExtension(fn, ext)
end
# save it
func = get(_savemap, ext) do
error("Unsupported extension $ext with filename ", fn)
end
func(plt, fn)
end
savefig(fn::@compat(AbstractString)) = savefig(current(), fn)
# savepng(args...; kw...) = savepng(current(), args...; kw...)
# savepng(plt::PlottingObject, fn::@compat(AbstractString); kw...) = (io = open(fn, "w"); writemime(io, MIME("image/png"), plt); close(io))
# ---------------------------------------------------------
gui(plt::PlottingObject = current()) = display(PlotsDisplay(), plt)
# override the REPL display to open a gui window
Base.display(::Base.REPL.REPLDisplay, ::MIME"text/plain", plt::PlottingObject) = gui(plt)
# ---------------------------------------------------------

View File

@ -7,70 +7,70 @@
# gadfly() = backend(:gadfly)
# supportedArgs(::GadflyPackage) = setdiff(_allArgs, [:heatmap_c, :pos, :screen, :yrightlabel])
supportedArgs(::GadflyPackage) = [
:annotation,
# :axis,
:background_color,
:color,
:color_palette,
:fillrange,
:fillcolor,
:fillopacity,
:foreground_color,
:group,
:label,
:layout,
:legend,
:linestyle,
:linetype,
:linewidth,
:lineopacity,
:markershape,
:markercolor,
:markersize,
:markeropacity,
:n,
:nbins,
:nc,
:nr,
# :pos,
:smooth,
:show,
:size,
:title,
:windowtitle,
:x,
:xlabel,
:xlims,
:xticks,
:y,
:ylabel,
:ylims,
# :yrightlabel,
:yticks,
:xscale,
:yscale,
:xflip,
:yflip,
:z,
:tickfont,
:guidefont,
:legendfont,
:grid,
]
supportedAxes(::GadflyPackage) = [:auto, :left]
supportedTypes(::GadflyPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :ohlc]
supportedStyles(::GadflyPackage) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
supportedMarkers(::GadflyPackage) = vcat(_allMarkers, Shape)
supportedScales(::GadflyPackage) = [:identity, :log, :log2, :log10, :asinh, :sqrt]
# # supportedArgs(::GadflyPackage) = setdiff(_allArgs, [:heatmap_c, :pos, :screen, :yrightlabel])
# supportedArgs(::GadflyPackage) = [
# :annotation,
# # :axis,
# :background_color,
# :color,
# :color_palette,
# :fillrange,
# :fillcolor,
# :fillopacity,
# :foreground_color,
# :group,
# :label,
# :layout,
# :legend,
# :linestyle,
# :linetype,
# :linewidth,
# :lineopacity,
# :markershape,
# :markercolor,
# :markersize,
# :markeropacity,
# :n,
# :nbins,
# :nc,
# :nr,
# # :pos,
# :smooth,
# :show,
# :size,
# :title,
# :windowtitle,
# :x,
# :xlabel,
# :xlims,
# :xticks,
# :y,
# :ylabel,
# :ylims,
# # :yrightlabel,
# :yticks,
# :xscale,
# :yscale,
# :xflip,
# :yflip,
# :z,
# :tickfont,
# :guidefont,
# :legendfont,
# :grid,
# ]
# supportedAxes(::GadflyPackage) = [:auto, :left]
# supportedTypes(::GadflyPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :ohlc]
# supportedStyles(::GadflyPackage) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
# supportedMarkers(::GadflyPackage) = vcat(_allMarkers, Shape)
# supportedScales(::GadflyPackage) = [:identity, :log, :log2, :log10, :asinh, :sqrt]
# ---------------------------------------------------------------------------
function createGadflyPlotObject(d::Dict)
@eval import DataFrames
# @eval import DataFrames
gplt = Gadfly.Plot()
gplt.mapping = Dict()
@ -588,7 +588,7 @@ end
# create the underlying object (each backend will do this differently)
function buildSubplotObject!(subplt::Subplot{GadflyPackage}, isbefore::Bool)
isbefore && return false
isbefore && return false # wait until after plotting to create the subplots
subplt.o = nothing
true
end
@ -637,12 +637,30 @@ function setGadflyDisplaySize(w,h)
Compose.set_default_graphic_size(w * Compose.px, h * Compose.px)
end
function Base.writemime(io::IO, ::MIME"image/png", plt::Plot{GadflyPackage})
# -------------------------------------------------------------------------
function dowritemime{P<:GadflyOrImmerse}(io::IO, func, plt::PlottingObject{P})
gplt = getGadflyContext(plt)
setGadflyDisplaySize(plt.initargs[:size]...)
Gadfly.draw(Gadfly.PNG(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt)
Gadfly.draw(func(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt)
end
getGadflyWriteFunc(::MIME"image/png") = Gadfly.PNG
getGadflyWriteFunc(::MIME"image/svg+xml") = Gadfly.SVG
getGadflyWriteFunc(::MIME"text/html") = Gadfly.SVGJS
getGadflyWriteFunc(::MIME"application/pdf") = Gadfly.PDF
getGadflyWriteFunc(::MIME"application/postscript") = Gadfly.PS
getGadflyWriteFunc(m::MIME) = error("Unsupported in Gadfly/Immerse: ", m)
for mime in (MIME"image/png", MIME"image/svg+xml", MIME"text/html", MIME"application/pdf", MIME"application/postscript")
@eval function Base.writemime{P<:GadflyOrImmerse}(io::IO, ::$mime, plt::PlottingObject{P})
func = getGadflyWriteFunc($mime())
dowritemime(io, func, plt)
end
end
function Base.display(::PlotsDisplay, plt::Plot{GadflyPackage})
setGadflyDisplaySize(plt.initargs[:size]...)
@ -651,12 +669,6 @@ end
function Base.writemime(io::IO, ::MIME"image/png", plt::Subplot{GadflyPackage})
gplt = getGadflyContext(plt)
setGadflyDisplaySize(plt.initargs[1][:size]...)
Gadfly.draw(Gadfly.PNG(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt)
end
function Base.display(::PlotsDisplay, subplt::Subplot{GadflyPackage})
setGadflyDisplaySize(subplt.initargs[1][:size]...)
ctx = buildGadflySubplotContext(subplt)

View File

@ -7,12 +7,12 @@
# immerse() = backend(:immerse)
supportedArgs(::ImmersePackage) = supportedArgs(GadflyPackage())
supportedAxes(::ImmersePackage) = supportedAxes(GadflyPackage())
supportedTypes(::ImmersePackage) = supportedTypes(GadflyPackage())
supportedStyles(::ImmersePackage) = supportedStyles(GadflyPackage())
supportedMarkers(::ImmersePackage) = supportedMarkers(GadflyPackage())
supportedScales(::ImmersePackage) = supportedScales(GadflyPackage())
# supportedArgs(::ImmersePackage) = supportedArgs(GadflyPackage())
# supportedAxes(::ImmersePackage) = supportedAxes(GadflyPackage())
# supportedTypes(::ImmersePackage) = supportedTypes(GadflyPackage())
# supportedStyles(::ImmersePackage) = supportedStyles(GadflyPackage())
# supportedMarkers(::ImmersePackage) = supportedMarkers(GadflyPackage())
# supportedScales(::ImmersePackage) = supportedScales(GadflyPackage())
function createImmerseFigure(d::Dict)
@ -150,11 +150,17 @@ end
getGadflyContext(plt::Plot{ImmersePackage}) = plt.o[2]
getGadflyContext(subplt::Subplot{ImmersePackage}) = buildGadflySubplotContext(subplt)
function Base.writemime(io::IO, ::MIME"image/png", plt::Plot{ImmersePackage})
gplt = getGadflyContext(plt)
setGadflyDisplaySize(plt.initargs[:size]...)
Gadfly.draw(Gadfly.PNG(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt)
end
# function Base.writemime(io::IO, ::MIME"image/png", plt::Plot{ImmersePackage})
# gplt = getGadflyContext(plt)
# setGadflyDisplaySize(plt.initargs[:size]...)
# Gadfly.draw(Gadfly.PNG(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt)
# end
# function Base.writemime(io::IO, ::MIME"image/svg+xml", plt::Plot{ImmersePackage})
# gplt = getGadflyContext(plt)
# setGadflyDisplaySize(plt.initargs[:size]...)
# Gadfly.draw(Gadfly.SVG(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt)
# end
function Base.display(::PlotsDisplay, plt::Plot{ImmersePackage})
@ -170,11 +176,18 @@ function Base.display(::PlotsDisplay, plt::Plot{ImmersePackage})
end
function Base.writemime(io::IO, ::MIME"image/png", plt::Subplot{ImmersePackage})
gplt = getGadflyContext(plt)
setGadflyDisplaySize(plt.initargs[1][:size]...)
Gadfly.draw(Gadfly.PNG(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt)
end
# function Base.writemime(io::IO, ::MIME"image/png", plt::Subplot{ImmersePackage})
# gplt = getGadflyContext(plt)
# setGadflyDisplaySize(plt.initargs[1][:size]...)
# Gadfly.draw(Gadfly.PNG(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt)
# end
# function Base.writemime(io::IO, ::MIME"image/svg+xml", plt::Subplot{ImmersePackage})
# gplt = getGadflyContext(plt)
# setGadflyDisplaySize(plt.initargs[1][:size]...)
# Gadfly.draw(Gadfly.SVG(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt)
# end
function Base.display(::PlotsDisplay, subplt::Subplot{ImmersePackage})

View File

@ -8,65 +8,65 @@
# -------------------------------
supportedArgs(::PyPlotPackage) = [
:annotation,
# :args,
:axis,
:background_color,
:color,
:color_palette,
:fillrange,
:fillcolor,
:foreground_color,
:group,
# :heatmap_c,
# :kwargs,
:label,
:layout,
:legend,
:linestyle,
:linetype,
:linewidth,
:markershape,
:markercolor,
:markersize,
:n,
:nbins,
:nc,
:nr,
# :pos,
# :smooth,
# :ribbon,
:show,
:size,
:title,
:windowtitle,
:x,
:xlabel,
:xlims,
:xticks,
:y,
:ylabel,
:ylims,
:yrightlabel,
:yticks,
:xscale,
:yscale,
:xflip,
:yflip,
:z,
:tickfont,
:guidefont,
:legendfont,
# :grid,
]
supportedAxes(::PyPlotPackage) = _allAxes
supportedTypes(::PyPlotPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline]
supportedStyles(::PyPlotPackage) = [:auto, :solid, :dash, :dot, :dashdot]
# supportedMarkers(::PyPlotPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :hexagon]
supportedMarkers(::PyPlotPackage) = vcat(_allMarkers, Shape)
supportedScales(::PyPlotPackage) = [:identity, :log, :log2, :log10]
subplotSupported(::PyPlotPackage) = true
# supportedArgs(::PyPlotPackage) = [
# :annotation,
# # :args,
# :axis,
# :background_color,
# :color,
# :color_palette,
# :fillrange,
# :fillcolor,
# :foreground_color,
# :group,
# # :heatmap_c,
# # :kwargs,
# :label,
# :layout,
# :legend,
# :linestyle,
# :linetype,
# :linewidth,
# :markershape,
# :markercolor,
# :markersize,
# :n,
# :nbins,
# :nc,
# :nr,
# # :pos,
# # :smooth,
# # :ribbon,
# :show,
# :size,
# :title,
# :windowtitle,
# :x,
# :xlabel,
# :xlims,
# :xticks,
# :y,
# :ylabel,
# :ylims,
# :yrightlabel,
# :yticks,
# :xscale,
# :yscale,
# :xflip,
# :yflip,
# :z,
# :tickfont,
# :guidefont,
# :legendfont,
# # :grid,
# ]
# supportedAxes(::PyPlotPackage) = _allAxes
# supportedTypes(::PyPlotPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline]
# supportedStyles(::PyPlotPackage) = [:auto, :solid, :dash, :dot, :dashdot]
# # supportedMarkers(::PyPlotPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :hexagon]
# supportedMarkers(::PyPlotPackage) = vcat(_allMarkers, Shape)
# supportedScales(::PyPlotPackage) = [:identity, :log, :log2, :log10]
# subplotSupported(::PyPlotPackage) = true
# convert colorant to 4-tuple RGBA
getPyPlotColor(c::Colorant) = map(f->float(f(c)), (red, green, blue, alpha))
@ -556,10 +556,18 @@ function finalizePlot(plt::Plot{PyPlotPackage})
PyPlot.draw()
end
function Base.writemime(io::IO, m::MIME"image/png", plt::Plot{PyPlotPackage})
finalizePlot(plt)
writemime(io, m, getfig(plt.o))
end
# # allow for writing any supported mime
# for mime in keys(PyPlot.aggformats)
# @eval function Base.writemime(io::IO, m::MIME{symbol{$mime}}, plt::Plot{PyPlotPackage})
# finalizePlot(plt)
# writemime(io, m, getfig(plt.o))
# end
# end
# function Base.writemime(io::IO, m::@compat(Union{MIME"image/svg+xml", MIME"image/png"}, plt::Plot{PyPlotPackage})
# finalizePlot(plt)
# writemime(io, m, getfig(plt.o))
# end
function Base.display(::PlotsDisplay, plt::Plot{PyPlotPackage})
@ -580,8 +588,16 @@ function Base.display(::PlotsDisplay, subplt::Subplot{PyPlotPackage})
display(getfig(subplt.o))
end
function Base.writemime(io::IO, m::MIME"image/png", subplt::Subplot{PyPlotPackage})
finalizePlot(subplt)
writemime(io, m, getfig(subplt.o))
# allow for writing any supported mime
for mime in (MIME"image/png", MIME"image/svg+xml", MIME"text/html", MIME"application/pdf", MIME"application/postscript")
@eval function Base.writemime(io::IO, ::$mime, plt::PlottingObject{PyPlotPackage})
finalizePlot(plt)
writemime(io, $mime(), getfig(plt.o))
end
end
# function Base.writemime(io::IO, m::MIME"image/png", subplt::Subplot{PyPlotPackage})
# finalizePlot(subplt)
# writemime(io, m, getfig(subplt.o))
# end

View File

@ -6,58 +6,58 @@
# export qwt
# qwt() = backend(:qwt)
# supportedArgs(::QwtPackage) = setdiff(_allArgs, [:xlims, :ylims, :xticks, :yticks])
supportedArgs(::QwtPackage) = [
:annotation,
# :args,
:axis,
:background_color,
:color,
:color_palette,
:fillrange,
:fillcolor,
:foreground_color,
:group,
# :heatmap_c,
# :kwargs,
:label,
:layout,
:legend,
:linestyle,
:linetype,
:linewidth,
:markershape,
:markercolor,
:markersize,
:n,
:nbins,
:nc,
:nr,
:pos,
:smooth,
# :ribbon,
:show,
:size,
:title,
:windowtitle,
:x,
:xlabel,
:xlims,
:xticks,
:y,
:ylabel,
:ylims,
:yrightlabel,
:yticks,
:xscale,
:yscale,
# :xflip,
# :yflip,
# :z,
]
supportedTypes(::QwtPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline]
supportedMarkers(::QwtPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :star8, :hexagon]
supportedScales(::QwtPackage) = [:identity, :log10]
# # supportedArgs(::QwtPackage) = setdiff(_allArgs, [:xlims, :ylims, :xticks, :yticks])
# supportedArgs(::QwtPackage) = [
# :annotation,
# # :args,
# :axis,
# :background_color,
# :color,
# :color_palette,
# :fillrange,
# :fillcolor,
# :foreground_color,
# :group,
# # :heatmap_c,
# # :kwargs,
# :label,
# :layout,
# :legend,
# :linestyle,
# :linetype,
# :linewidth,
# :markershape,
# :markercolor,
# :markersize,
# :n,
# :nbins,
# :nc,
# :nr,
# :pos,
# :smooth,
# # :ribbon,
# :show,
# :size,
# :title,
# :windowtitle,
# :x,
# :xlabel,
# :xlims,
# :xticks,
# :y,
# :ylabel,
# :ylims,
# :yrightlabel,
# :yticks,
# :xscale,
# :yscale,
# # :xflip,
# # :yflip,
# # :z,
# ]
# supportedTypes(::QwtPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline]
# supportedMarkers(::QwtPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :star8, :hexagon]
# supportedScales(::QwtPackage) = [:identity, :log10]
# -------------------------------

309
src/backends/supported.jl Normal file
View File

@ -0,0 +1,309 @@
supportedArgs(::GadflyPackage) = [
:annotation,
# :axis,
:background_color,
:color,
:color_palette,
:fillrange,
:fillcolor,
:fillopacity,
:foreground_color,
:group,
:label,
:layout,
:legend,
:linestyle,
:linetype,
:linewidth,
:lineopacity,
:markershape,
:markercolor,
:markersize,
:markeropacity,
:n,
:nbins,
:nc,
:nr,
# :pos,
:smooth,
:show,
:size,
:title,
:windowtitle,
:x,
:xlabel,
:xlims,
:xticks,
:y,
:ylabel,
:ylims,
# :yrightlabel,
:yticks,
:xscale,
:yscale,
:xflip,
:yflip,
:z,
:tickfont,
:guidefont,
:legendfont,
:grid,
]
supportedAxes(::GadflyPackage) = [:auto, :left]
supportedTypes(::GadflyPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :ohlc]
supportedStyles(::GadflyPackage) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
supportedMarkers(::GadflyPackage) = vcat(_allMarkers, Shape)
supportedScales(::GadflyPackage) = [:identity, :log, :log2, :log10, :asinh, :sqrt]
# --------------------------------------------------------------------------------------
supportedArgs(::ImmersePackage) = supportedArgs(GadflyPackage())
supportedAxes(::ImmersePackage) = supportedAxes(GadflyPackage())
supportedTypes(::ImmersePackage) = supportedTypes(GadflyPackage())
supportedStyles(::ImmersePackage) = supportedStyles(GadflyPackage())
supportedMarkers(::ImmersePackage) = supportedMarkers(GadflyPackage())
supportedScales(::ImmersePackage) = supportedScales(GadflyPackage())
# --------------------------------------------------------------------------------------
supportedArgs(::PyPlotPackage) = [
:annotation,
# :args,
:axis,
:background_color,
:color,
:color_palette,
:fillrange,
:fillcolor,
:foreground_color,
:group,
# :heatmap_c,
# :kwargs,
:label,
:layout,
:legend,
:linestyle,
:linetype,
:linewidth,
:markershape,
:markercolor,
:markersize,
:n,
:nbins,
:nc,
:nr,
# :pos,
# :smooth,
# :ribbon,
:show,
:size,
:title,
:windowtitle,
:x,
:xlabel,
:xlims,
:xticks,
:y,
:ylabel,
:ylims,
:yrightlabel,
:yticks,
:xscale,
:yscale,
:xflip,
:yflip,
:z,
:tickfont,
:guidefont,
:legendfont,
# :grid,
]
supportedAxes(::PyPlotPackage) = _allAxes
supportedTypes(::PyPlotPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline]
supportedStyles(::PyPlotPackage) = [:auto, :solid, :dash, :dot, :dashdot]
# supportedMarkers(::PyPlotPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :hexagon]
supportedMarkers(::PyPlotPackage) = vcat(_allMarkers, Shape)
supportedScales(::PyPlotPackage) = [:identity, :log, :log2, :log10]
subplotSupported(::PyPlotPackage) = true
# --------------------------------------------------------------------------------------
supportedArgs(::QwtPackage) = [
:annotation,
# :args,
:axis,
:background_color,
:color,
:color_palette,
:fillrange,
:fillcolor,
:foreground_color,
:group,
# :heatmap_c,
# :kwargs,
:label,
:layout,
:legend,
:linestyle,
:linetype,
:linewidth,
:markershape,
:markercolor,
:markersize,
:n,
:nbins,
:nc,
:nr,
:pos,
:smooth,
# :ribbon,
:show,
:size,
:title,
:windowtitle,
:x,
:xlabel,
:xlims,
:xticks,
:y,
:ylabel,
:ylims,
:yrightlabel,
:yticks,
:xscale,
:yscale,
# :xflip,
# :yflip,
# :z,
]
supportedTypes(::QwtPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline]
supportedMarkers(::QwtPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :star8, :hexagon]
supportedScales(::QwtPackage) = [:identity, :log10]
# --------------------------------------------------------------------------------------
supportedArgs(::UnicodePlotsPackage) = [
# :annotation,
# :args,
# :axis,
# :background_color,
# :color,
# :fill,
# :foreground_color,
:group,
# :heatmap_c,
# :kwargs,
:label,
# :layout,
:legend,
:linestyle,
:linetype,
# :linewidth,
:markershape,
# :markercolor,
# :markersize,
# :n,
:nbins,
# :nc,
# :nr,
# :pos,
# :reg,
# :ribbon,
:show,
:size,
:title,
:windowtitle,
:x,
:xlabel,
:xlims,
# :xticks,
:y,
:ylabel,
:ylims,
# :yrightlabel,
# :yticks,
# :xscale,
# :yscale,
# :xflip,
# :yflip,
# :z,
]
supportedAxes(::UnicodePlotsPackage) = [:auto, :left]
supportedTypes(::UnicodePlotsPackage) = [:none, :line, :path, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline]
supportedStyles(::UnicodePlotsPackage) = [:auto, :solid]
supportedMarkers(::UnicodePlotsPackage) = [:none, :auto, :ellipse]
supportedScales(::UnicodePlotsPackage) = [:identity]
# --------------------------------------------------------------------------------------
supportedArgs(::WinstonPackage) = [
:annotation,
# :args,
# :axis,
# :background_color,
:color,
:color_palette,
:fillrange,
:fillcolor,
# :foreground_color,
:group,
# :heatmap_c,
# :kwargs,
:label,
# :layout,
:legend,
:linestyle,
:linetype,
:linewidth,
:markershape,
:markercolor,
:markersize,
# :n,
:nbins,
# :nc,
# :nr,
# :pos,
:smooth,
# :ribbon,
:show,
:size,
:title,
:windowtitle,
:x,
:xlabel,
:xlims,
# :xticks,
:y,
:ylabel,
:ylims,
# :yrightlabel,
# :yticks,
:xscale,
:yscale,
# :xflip,
# :yflip,
# :z,
]
supportedAxes(::WinstonPackage) = [:auto, :left]
supportedTypes(::WinstonPackage) = [:none, :line, :path, :sticks, :scatter, :hist, :bar]
supportedStyles(::WinstonPackage) = [:auto, :solid, :dash, :dot, :dashdot]
supportedMarkers(::WinstonPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5]
supportedScales(::WinstonPackage) = [:identity, :log10]
subplotSupported(::WinstonPackage) = false
# --------------------------------------------------------------------------------------

View File

@ -8,58 +8,58 @@
# -------------------------------
# supportedArgs(::UnicodePlotsPackage) = setdiff(_allArgs, [:reg, :heatmap_c, :fill, :pos, :xlims, :ylims, :xticks, :yticks])
supportedArgs(::UnicodePlotsPackage) = [
# :annotation,
# :args,
# :axis,
# :background_color,
# :color,
# :fill,
# :foreground_color,
:group,
# :heatmap_c,
# :kwargs,
:label,
# :layout,
:legend,
:linestyle,
:linetype,
# :linewidth,
:markershape,
# :markercolor,
# :markersize,
# :n,
:nbins,
# :nc,
# :nr,
# :pos,
# :reg,
# :ribbon,
:show,
:size,
:title,
:windowtitle,
:x,
:xlabel,
:xlims,
# :xticks,
:y,
:ylabel,
:ylims,
# :yrightlabel,
# :yticks,
# :xscale,
# :yscale,
# :xflip,
# :yflip,
# :z,
]
supportedAxes(::UnicodePlotsPackage) = [:auto, :left]
supportedTypes(::UnicodePlotsPackage) = [:none, :line, :path, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline]
supportedStyles(::UnicodePlotsPackage) = [:auto, :solid]
supportedMarkers(::UnicodePlotsPackage) = [:none, :auto, :ellipse]
supportedScales(::UnicodePlotsPackage) = [:identity]
# # supportedArgs(::UnicodePlotsPackage) = setdiff(_allArgs, [:reg, :heatmap_c, :fill, :pos, :xlims, :ylims, :xticks, :yticks])
# supportedArgs(::UnicodePlotsPackage) = [
# # :annotation,
# # :args,
# # :axis,
# # :background_color,
# # :color,
# # :fill,
# # :foreground_color,
# :group,
# # :heatmap_c,
# # :kwargs,
# :label,
# # :layout,
# :legend,
# :linestyle,
# :linetype,
# # :linewidth,
# :markershape,
# # :markercolor,
# # :markersize,
# # :n,
# :nbins,
# # :nc,
# # :nr,
# # :pos,
# # :reg,
# # :ribbon,
# :show,
# :size,
# :title,
# :windowtitle,
# :x,
# :xlabel,
# :xlims,
# # :xticks,
# :y,
# :ylabel,
# :ylims,
# # :yrightlabel,
# # :yticks,
# # :xscale,
# # :yscale,
# # :xflip,
# # :yflip,
# # :z,
# ]
# supportedAxes(::UnicodePlotsPackage) = [:auto, :left]
# supportedTypes(::UnicodePlotsPackage) = [:none, :line, :path, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline]
# supportedStyles(::UnicodePlotsPackage) = [:auto, :solid]
# supportedMarkers(::UnicodePlotsPackage) = [:none, :auto, :ellipse]
# supportedScales(::UnicodePlotsPackage) = [:identity]

View File

@ -30,60 +30,60 @@
)
supportedArgs(::WinstonPackage) = [
:annotation,
# :args,
# :axis,
# :background_color,
:color,
:color_palette,
:fillrange,
:fillcolor,
# :foreground_color,
:group,
# :heatmap_c,
# :kwargs,
:label,
# :layout,
:legend,
:linestyle,
:linetype,
:linewidth,
:markershape,
:markercolor,
:markersize,
# :n,
:nbins,
# :nc,
# :nr,
# :pos,
:smooth,
# :ribbon,
:show,
:size,
:title,
:windowtitle,
:x,
:xlabel,
:xlims,
# :xticks,
:y,
:ylabel,
:ylims,
# :yrightlabel,
# :yticks,
:xscale,
:yscale,
# :xflip,
# :yflip,
# :z,
]
supportedAxes(::WinstonPackage) = [:auto, :left]
supportedTypes(::WinstonPackage) = [:none, :line, :path, :sticks, :scatter, :hist, :bar]
supportedStyles(::WinstonPackage) = [:auto, :solid, :dash, :dot, :dashdot]
supportedMarkers(::WinstonPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5]
supportedScales(::WinstonPackage) = [:identity, :log10]
subplotSupported(::WinstonPackage) = false
# supportedArgs(::WinstonPackage) = [
# :annotation,
# # :args,
# # :axis,
# # :background_color,
# :color,
# :color_palette,
# :fillrange,
# :fillcolor,
# # :foreground_color,
# :group,
# # :heatmap_c,
# # :kwargs,
# :label,
# # :layout,
# :legend,
# :linestyle,
# :linetype,
# :linewidth,
# :markershape,
# :markercolor,
# :markersize,
# # :n,
# :nbins,
# # :nc,
# # :nr,
# # :pos,
# :smooth,
# # :ribbon,
# :show,
# :size,
# :title,
# :windowtitle,
# :x,
# :xlabel,
# :xlims,
# # :xticks,
# :y,
# :ylabel,
# :ylims,
# # :yrightlabel,
# # :yticks,
# :xscale,
# :yscale,
# # :xflip,
# # :yflip,
# # :z,
# ]
# supportedAxes(::WinstonPackage) = [:auto, :left]
# supportedTypes(::WinstonPackage) = [:none, :line, :path, :sticks, :scatter, :hist, :bar]
# supportedStyles(::WinstonPackage) = [:auto, :solid, :dash, :dot, :dashdot]
# supportedMarkers(::WinstonPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5]
# supportedScales(::WinstonPackage) = [:identity, :log10]
# subplotSupported(::WinstonPackage) = false
function preparePlotUpdate(plt::Plot{WinstonPackage})

104
src/output.jl Normal file
View File

@ -0,0 +1,104 @@
defaultOutputFormat(plt::PlottingObject) = "png"
function png(plt::PlottingObject, fn::@compat(AbstractString))
fn = addExtension(fn, "png")
io = open(fn, "w")
writemime(io, MIME("image/png"), plt)
close(io)
end
png(fn::@compat(AbstractString)) = png(current(), fn)
function svg(plt::PlottingObject, fn::@compat(AbstractString))
fn = addExtension(fn, "svg")
io = open(fn, "w")
writemime(io, MIME("image/svg+xml"), plt)
close(io)
end
svg(fn::@compat(AbstractString)) = svg(current(), fn)
function pdf(plt::PlottingObject, fn::@compat(AbstractString))
fn = addExtension(fn, "pdf")
io = open(fn, "w")
writemime(io, MIME("application/pdf"), plt)
close(io)
end
pdf(fn::@compat(AbstractString)) = pdf(current(), fn)
function ps(plt::PlottingObject, fn::@compat(AbstractString))
fn = addExtension(fn, "ps")
io = open(fn, "w")
writemime(io, MIME("application/postscript"), plt)
close(io)
end
ps(fn::@compat(AbstractString)) = ps(current(), fn)
# ----------------------------------------------------------------
@compat const _savemap = Dict(
"png" => png,
"svg" => svg,
"pdf" => pdf,
"ps" => ps,
)
function getExtension(fn::@compat(AbstractString))
pieces = split(fn, ".")
length(pieces) > 1 || error("Can't extract file extension: ", fn)
ext = pieces[end]
haskey(_savemap, ext) || error("Invalid file extension: ", fn)
ext
end
function addExtension(fn::@compat(AbstractString), ext::@compat(AbstractString))
try
oldext = getExtension(fn)
if oldext == ext
return fn
else
return "$fn.$ext"
end
catch
return "$fn.$ext"
end
end
function savefig(plt::PlottingObject, fn::@compat(AbstractString))
# get the extension
local ext
try
ext = getExtension(fn)
catch
# if we couldn't extract the extension, add the default
ext = defaultOutputFormat(plt)
fn = addExtension(fn, ext)
end
# save it
func = get(_savemap, ext) do
error("Unsupported extension $ext with filename ", fn)
end
func(plt, fn)
end
savefig(fn::@compat(AbstractString)) = savefig(current(), fn)
# savepng(args...; kw...) = savepng(current(), args...; kw...)
# savepng(plt::PlottingObject, fn::@compat(AbstractString); kw...) = (io = open(fn, "w"); writemime(io, MIME("image/png"), plt); close(io))
# ---------------------------------------------------------
gui(plt::PlottingObject = current()) = display(PlotsDisplay(), plt)
# override the REPL display to open a gui window
Base.display(::Base.REPL.REPLDisplay, ::MIME"text/plain", plt::PlottingObject) = gui(plt)

View File

@ -57,6 +57,8 @@ function plot(args...; kw...)
plt = plot(pkg; getPlotArgs(pkg, d, 1)...) # create a new, blank plot
delete!(d, :background_color)
# print(d)
# return plt
plot!(plt, args...; d...) # add to it
end
@ -80,6 +82,9 @@ end
# this adds to a specific plot... most plot commands will flow through here
function plot!(plt::Plot, args...; kw...)
# println(plt)
# println(args)
# println(kw)
d = Dict(kw)
preprocessArgs!(d)

View File

@ -7,6 +7,8 @@ immutable QwtPackage <: PlottingPackage end
immutable UnicodePlotsPackage <: PlottingPackage end
immutable WinstonPackage <: PlottingPackage end
typealias GadflyOrImmerse @compat(Union{GadflyPackage, ImmersePackage})
export
gadfly,
immerse,
@ -22,6 +24,7 @@ qwt() = backend(:qwt)
unicodeplots() = backend(:unicodeplots)
winston() = backend(:winston)
include("backends/supported.jl")
include("backends/qwt.jl")
include("backends/gadfly.jl")
@ -114,6 +117,7 @@ end
Returns the current plotting package name. Initializes package on first call.
"""
function backend()
# error()
currentBackendSymbol = CURRENT_BACKEND.sym
if !(currentBackendSymbol in INITIALIZED_BACKENDS)
@ -125,16 +129,18 @@ function backend()
@eval import Qwt
@eval export Qwt
catch err
error("Couldn't import Qwt. Install it with: Pkg.clone(\"https://github.com/tbreloff/Qwt.jl.git\")\n (Note: also requires pyqt and pyqwt).\n Error: ", err)
warn("Couldn't import Qwt. Install it with: Pkg.clone(\"https://github.com/tbreloff/Qwt.jl.git\")\n (Note: also requires pyqt and pyqwt).")
rethrow(err)
end
elseif currentBackendSymbol == :gadfly
try
@eval import Gadfly, Compose
@eval export Gadfly, Compose
@eval import Gadfly, Compose, DataFrames
@eval export Gadfly, Compose, DataFrames
@eval include(joinpath(Pkg.dir("Plots"), "src", "backends", "gadfly_shapes.jl"))
catch err
error("Couldn't import Gadfly. Install it with: Pkg.add(\"Gadfly\").\n Error: ", err)
warn("Couldn't import Gadfly. Install it with: Pkg.add(\"Gadfly\").")
rethrow(err)
end
elseif currentBackendSymbol == :unicodeplots
@ -142,7 +148,8 @@ function backend()
@eval import UnicodePlots
@eval export UnicodePlots
catch err
error("Couldn't import UnicodePlots. Install it with: Pkg.add(\"UnicodePlots\").\n Error: ", err)
warn("Couldn't import UnicodePlots. Install it with: Pkg.add(\"UnicodePlots\").")
rethrow(err)
end
elseif currentBackendSymbol == :pyplot
@ -154,7 +161,8 @@ function backend()
PyPlot.ioff()
end
catch err
error("Couldn't import PyPlot. Install it with: Pkg.add(\"PyPlot\").\n Error: ", err)
warn("Couldn't import PyPlot. Install it with: Pkg.add(\"PyPlot\").")
rethrow(err)
end
elseif currentBackendSymbol == :immerse
@ -163,7 +171,9 @@ function backend()
@eval export Immerse, Gadfly, Compose, Gtk
@eval include(joinpath(Pkg.dir("Plots"), "src", "backends", "gadfly_shapes.jl"))
catch err
error("Couldn't import Immerse. Install it with: Pkg.add(\"Immerse\").\n Error: ", err)
# error("Couldn't import Immerse. Install it with: Pkg.add(\"Immerse\").\n Error: ", err)
warn("Couldn't import Immerse. Install it with: Pkg.add(\"Immerse\").")
rethrow(err)
end
elseif currentBackendSymbol == :winston
@ -171,16 +181,15 @@ function backend()
@eval ENV["WINSTON_OUTPUT"] = "gtk"
@eval import Winston, Gtk
@eval export Winston, Gtk
#@eval Winston._winston_config.defaults["output_surface"] = "gtk"
catch err
error("Couldn't import Winston. Install it with: Pkg.add(\"Winston\").\n Error: ", err)
warn("Couldn't import Winston. Install it with: Pkg.add(\"Winston\").")
rethrow(err)
end
else
error("Unknown backend $currentBackendSymbol. Choose from: $BACKENDS")
end
push!(INITIALIZED_BACKENDS, currentBackendSymbol)
# println("[Plots.jl] done.")
end
CURRENT_BACKEND.pkg

View File

@ -51,7 +51,7 @@ function isTempImageCorrect(tmpfn, reffn)
end
function image_comparison_tests(pkg::Symbol, idx::Int; debug = true)
function image_comparison_tests(pkg::Symbol, idx::Int; debug = true, sigma = [0,0], eps = 1e-3)
# first
Plots._debugMode.on = debug
@ -72,7 +72,25 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = true)
refimg = imread(reffn)
# run the test
@test_approx_eq_sigma_eps(tmpimg, refimg, sigma, eps)
# NOTE: sigma is a 2-length vector with x/y values for the number of pixels
# to blur together when comparing images
try
# run the comparison test... a difference will throw an error
@test_approx_eq_sigma_eps(tmpimg, refimg, sigma, eps)
catch ex
if isinteractive()
# if we're in interactive mode, open a popup and give us a chance to examine the images
if isTempImageCorrect(tmpfn, reffn)
return
end
end
# if we rejected the image, or if we're in automated tests, throw the error
throw(ex)
end
end
function image_comparison_tests(pkg::Symbol; debug = false)