commit
dd7b09552a
22
src/args.jl
22
src/args.jl
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
const _allAxes = [:auto, :left, :right]
|
const _allAxes = [:auto, :left, :right]
|
||||||
@compat const _axesAliases = Dict(
|
@compat const _axesAliases = Dict(
|
||||||
:a => :auto,
|
:a => :auto,
|
||||||
:l => :left,
|
:l => :left,
|
||||||
:r => :right
|
:r => :right
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -138,7 +138,8 @@ _seriesDefaults[:y] = nothing
|
|||||||
_seriesDefaults[:z] = nothing # depth for contour, surface, etc
|
_seriesDefaults[:z] = nothing # depth for contour, surface, etc
|
||||||
_seriesDefaults[:zcolor] = nothing # value for color scale
|
_seriesDefaults[:zcolor] = nothing # value for color scale
|
||||||
# _seriesDefaults[:surface] = nothing
|
# _seriesDefaults[:surface] = nothing
|
||||||
_seriesDefaults[:nlevels] = 15
|
# _seriesDefaults[:nlevels] = 15
|
||||||
|
_seriesDefaults[:levels] = 15
|
||||||
_seriesDefaults[:orientation] = :vertical
|
_seriesDefaults[:orientation] = :vertical
|
||||||
|
|
||||||
|
|
||||||
@ -283,6 +284,9 @@ end
|
|||||||
:foreground_colour => :foreground_color,
|
:foreground_colour => :foreground_color,
|
||||||
:regression => :smooth,
|
:regression => :smooth,
|
||||||
:reg => :smooth,
|
:reg => :smooth,
|
||||||
|
:nlevels => :levels,
|
||||||
|
:nlev => :levels,
|
||||||
|
:levs => :levels,
|
||||||
:xlim => :xlims,
|
:xlim => :xlims,
|
||||||
:xlimit => :xlims,
|
:xlimit => :xlims,
|
||||||
:xlimits => :xlims,
|
:xlimits => :xlims,
|
||||||
@ -407,7 +411,7 @@ function processLineArg(d::Dict, arg)
|
|||||||
# linetype
|
# linetype
|
||||||
if trueOrAllTrue(a -> get(_typeAliases, a, a) in _allTypes, arg)
|
if trueOrAllTrue(a -> get(_typeAliases, a, a) in _allTypes, arg)
|
||||||
d[:linetype] = arg
|
d[:linetype] = arg
|
||||||
|
|
||||||
# linestyle
|
# linestyle
|
||||||
elseif trueOrAllTrue(a -> get(_styleAliases, a, a) in _allStyles, arg)
|
elseif trueOrAllTrue(a -> get(_styleAliases, a, a) in _allStyles, arg)
|
||||||
d[:linestyle] = arg
|
d[:linestyle] = arg
|
||||||
@ -446,7 +450,7 @@ function processMarkerArg(d::Dict, arg)
|
|||||||
d[:markershape] = arg
|
d[:markershape] = arg
|
||||||
elseif trueOrAllTrue(a -> isa(a, Shape), arg)
|
elseif trueOrAllTrue(a -> isa(a, Shape), arg)
|
||||||
d[:markershape] = arg
|
d[:markershape] = arg
|
||||||
|
|
||||||
# stroke style
|
# stroke style
|
||||||
elseif trueOrAllTrue(a -> get(_styleAliases, a, a) in _allStyles, arg)
|
elseif trueOrAllTrue(a -> get(_styleAliases, a, a) in _allStyles, arg)
|
||||||
d[:markerstrokestyle] = arg
|
d[:markerstrokestyle] = arg
|
||||||
@ -473,7 +477,7 @@ function processMarkerArg(d::Dict, arg)
|
|||||||
# markercolor
|
# markercolor
|
||||||
elseif !handleColors!(d, arg, :markercolor)
|
elseif !handleColors!(d, arg, :markercolor)
|
||||||
warn("Skipped marker arg $arg.")
|
warn("Skipped marker arg $arg.")
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -493,7 +497,7 @@ end
|
|||||||
"Handle all preprocessing of args... break out colors/sizes/etc and replace aliases."
|
"Handle all preprocessing of args... break out colors/sizes/etc and replace aliases."
|
||||||
function preprocessArgs!(d::Dict)
|
function preprocessArgs!(d::Dict)
|
||||||
replaceAliases!(d, _keyAliases)
|
replaceAliases!(d, _keyAliases)
|
||||||
|
|
||||||
# handle axis args
|
# handle axis args
|
||||||
for axisletter in ("x", "y")
|
for axisletter in ("x", "y")
|
||||||
asym = symbol(axisletter * "axis")
|
asym = symbol(axisletter * "axis")
|
||||||
@ -590,7 +594,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function warnOnUnsupported(pkg::PlottingPackage, d::Dict)
|
function warnOnUnsupported(pkg::PlottingPackage, d::Dict)
|
||||||
(d[:axis] in supportedAxes(pkg)
|
(d[:axis] in supportedAxes(pkg)
|
||||||
|| warn("axis $(d[:axis]) is unsupported with $pkg. Choose from: $(supportedAxes(pkg))"))
|
|| warn("axis $(d[:axis]) is unsupported with $pkg. Choose from: $(supportedAxes(pkg))"))
|
||||||
(d[:linetype] == :none
|
(d[:linetype] == :none
|
||||||
|| d[:linetype] in supportedTypes(pkg)
|
|| d[:linetype] in supportedTypes(pkg)
|
||||||
@ -683,7 +687,7 @@ function getSeriesArgs(pkg::PlottingPackage, plotargs::Dict, kw, commandIndex::I
|
|||||||
d[k] = kwdict[k]
|
d[k] = kwdict[k]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if haskey(_typeAliases, d[:linetype])
|
if haskey(_typeAliases, d[:linetype])
|
||||||
d[:linetype] = _typeAliases[d[:linetype]]
|
d[:linetype] = _typeAliases[d[:linetype]]
|
||||||
end
|
end
|
||||||
|
|||||||
@ -44,7 +44,7 @@ function getLineGeom(d::Dict)
|
|||||||
elseif lt == :vline
|
elseif lt == :vline
|
||||||
Gadfly.Geom.vline
|
Gadfly.Geom.vline
|
||||||
elseif lt == :contour
|
elseif lt == :contour
|
||||||
Gadfly.Geom.contour(levels = d[:nlevels])
|
Gadfly.Geom.contour(levels = d[:levels])
|
||||||
else
|
else
|
||||||
nothing
|
nothing
|
||||||
end
|
end
|
||||||
@ -667,9 +667,10 @@ getGadflyWriteFunc(::MIME"image/svg+xml") = Gadfly.SVG
|
|||||||
# getGadflyWriteFunc(::MIME"text/html") = Gadfly.SVGJS
|
# getGadflyWriteFunc(::MIME"text/html") = Gadfly.SVGJS
|
||||||
getGadflyWriteFunc(::MIME"application/pdf") = Gadfly.PDF
|
getGadflyWriteFunc(::MIME"application/pdf") = Gadfly.PDF
|
||||||
getGadflyWriteFunc(::MIME"application/postscript") = Gadfly.PS
|
getGadflyWriteFunc(::MIME"application/postscript") = Gadfly.PS
|
||||||
|
getGadflyWriteFunc(::MIME"application/x-tex") = Gadfly.PGF
|
||||||
getGadflyWriteFunc(m::MIME) = error("Unsupported in Gadfly/Immerse: ", m)
|
getGadflyWriteFunc(m::MIME) = error("Unsupported in Gadfly/Immerse: ", m)
|
||||||
|
|
||||||
for mime in (MIME"image/png", MIME"image/svg+xml", MIME"application/pdf", MIME"application/postscript")
|
for mime in (MIME"image/png", MIME"image/svg+xml", MIME"application/pdf", MIME"application/postscript", MIME"application/x-tex")
|
||||||
@eval function Base.writemime{P<:GadflyOrImmerse}(io::IO, ::$mime, plt::PlottingObject{P})
|
@eval function Base.writemime{P<:GadflyOrImmerse}(io::IO, ::$mime, plt::PlottingObject{P})
|
||||||
func = getGadflyWriteFunc($mime())
|
func = getGadflyWriteFunc($mime())
|
||||||
dowritemime(io, func, plt)
|
dowritemime(io, func, plt)
|
||||||
|
|||||||
105
src/backends/glvisualize.jl
Normal file
105
src/backends/glvisualize.jl
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
|
||||||
|
|
||||||
|
# [WEBSITE]
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
immutable GLScreenWrapper
|
||||||
|
window
|
||||||
|
render
|
||||||
|
end
|
||||||
|
|
||||||
|
function _create_plot(pkg::GLVisualizePackage; 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
|
||||||
|
|
||||||
|
# TODO: this should be moved to the display method?
|
||||||
|
w,r=GLVisualize.glscreen()
|
||||||
|
@async r()
|
||||||
|
o = GLScreenWrapper(w,r)
|
||||||
|
|
||||||
|
Plot(o, pkg, 0, d, Dict[])
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function _add_series(::GLVisualizePackage, plt::Plot; kw...)
|
||||||
|
d = Dict(kw)
|
||||||
|
# TODO: add one series to the underlying package
|
||||||
|
push!(plt.seriesargs, d)
|
||||||
|
|
||||||
|
# TODO: this should be moved to the display method?
|
||||||
|
x, y, z = map(Float32, d[:x]), map(Float32, d[:y]), map(Float32, d[:z].surf)
|
||||||
|
viz = GLVisualize.visualize(x*ones(y)', ones(x)*y', z, :surface)
|
||||||
|
GLVisualize.view(viz)
|
||||||
|
|
||||||
|
plt
|
||||||
|
end
|
||||||
|
|
||||||
|
function _add_annotations{X,Y,V}(plt::Plot{GLVisualizePackage}, anns::AVec{@compat(Tuple{X,Y,V})})
|
||||||
|
for ann in anns
|
||||||
|
# TODO: add the annotation to the plot
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------
|
||||||
|
|
||||||
|
function _before_update_plot(plt::Plot{GLVisualizePackage})
|
||||||
|
end
|
||||||
|
|
||||||
|
# TODO: override this to update plot items (title, xlabel, etc) after creation
|
||||||
|
function _update_plot(plt::Plot{GLVisualizePackage}, d::Dict)
|
||||||
|
end
|
||||||
|
|
||||||
|
function _update_plot_pos_size(plt::PlottingObject{GLVisualizePackage}, d::Dict)
|
||||||
|
end
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------
|
||||||
|
|
||||||
|
# accessors for x/y data
|
||||||
|
|
||||||
|
function Base.getindex(plt::Plot{GLVisualizePackage}, i::Int)
|
||||||
|
# TODO:
|
||||||
|
# series = plt.o.lines[i]
|
||||||
|
# series.x, series.y
|
||||||
|
nothing, nothing
|
||||||
|
end
|
||||||
|
|
||||||
|
function Base.setindex!(plt::Plot{GLVisualizePackage}, xy::Tuple, i::Integer)
|
||||||
|
# TODO:
|
||||||
|
# series = plt.o.lines[i]
|
||||||
|
# series.x, series.y = xy
|
||||||
|
plt
|
||||||
|
end
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------
|
||||||
|
|
||||||
|
function _create_subplot(subplt::Subplot{GLVisualizePackage})
|
||||||
|
# TODO: build the underlying Subplot object. this is where you might layout the panes within a GUI window, for example
|
||||||
|
end
|
||||||
|
|
||||||
|
function _expand_limits(lims, plt::Plot{GLVisualizePackage}, isx::Bool)
|
||||||
|
# TODO: call expand limits for each plot data
|
||||||
|
end
|
||||||
|
|
||||||
|
function _remove_axis(plt::Plot{GLVisualizePackage}, isx::Bool)
|
||||||
|
# TODO: if plot is inner subplot, might need to remove ticks or axis labels
|
||||||
|
end
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------
|
||||||
|
|
||||||
|
function Base.writemime(io::IO, ::MIME"image/png", plt::PlottingObject{GLVisualizePackage})
|
||||||
|
# TODO: write a png to io
|
||||||
|
end
|
||||||
|
|
||||||
|
function Base.display(::PlotsDisplay, plt::Plot{GLVisualizePackage})
|
||||||
|
# TODO: display/show the plot
|
||||||
|
|
||||||
|
# NOTE: I think maybe this should be empty? We can start with the assumption that creating
|
||||||
|
# and adding to a plot will automatically open a window and draw to it, then the display
|
||||||
|
# wouldn't actually need to do anything
|
||||||
|
end
|
||||||
|
|
||||||
|
function Base.display(::PlotsDisplay, plt::Subplot{GLVisualizePackage})
|
||||||
|
# TODO: display/show the subplot
|
||||||
|
end
|
||||||
@ -176,8 +176,9 @@ function plotlyaxis(d::Dict, isx::Bool)
|
|||||||
ax
|
ax
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_plot_json(plt::Plot{PlotlyPackage})
|
# function get_plot_json(plt::Plot{PlotlyPackage})
|
||||||
d = plt.plotargs
|
# d = plt.plotargs
|
||||||
|
function plotly_layout(d::Dict)
|
||||||
d_out = Dict()
|
d_out = Dict()
|
||||||
|
|
||||||
bgcolor = webcolor(d[:background_color])
|
bgcolor = webcolor(d[:background_color])
|
||||||
@ -194,84 +195,6 @@ function get_plot_json(plt::Plot{PlotlyPackage})
|
|||||||
d_out[:xaxis] = plotlyaxis(d, true)
|
d_out[:xaxis] = plotlyaxis(d, true)
|
||||||
d_out[:yaxis] = plotlyaxis(d, false)
|
d_out[:yaxis] = plotlyaxis(d, false)
|
||||||
|
|
||||||
# # x-axis
|
|
||||||
# d_out[:xaxis] = Dict(
|
|
||||||
# :title => d[:xlabel],
|
|
||||||
# :showgrid => d[:grid],
|
|
||||||
# :zeroline => false,
|
|
||||||
# )
|
|
||||||
# merge!(d_out[:xaxis], if use_axis_field(d[:xticks])
|
|
||||||
# ax = Dict(
|
|
||||||
# :titlefont => plotlyfont(d[:guidefont]),
|
|
||||||
# :type => plotlyscale(d[:xscale]),
|
|
||||||
# :tickfont => plotlyfont(d[:tickfont]),
|
|
||||||
# :tickcolor => fgcolor,
|
|
||||||
# :linecolor => fgcolor,
|
|
||||||
# )
|
|
||||||
|
|
||||||
# # xlims
|
|
||||||
# lims = d[:xlims]
|
|
||||||
# if lims != :auto && limsType(lims) == :limits
|
|
||||||
# ax[:range] = lims
|
|
||||||
# end
|
|
||||||
|
|
||||||
# # xflip
|
|
||||||
# if d[:xflip]
|
|
||||||
# ax[:autorange] = "reversed"
|
|
||||||
# end
|
|
||||||
|
|
||||||
# # xticks
|
|
||||||
# ticks = d[:xticks]
|
|
||||||
# if ticks != :auto
|
|
||||||
# ttype = ticksType(ticks)
|
|
||||||
# if ttype == :ticks
|
|
||||||
# ax[:tickmode] = "array"
|
|
||||||
# ax[:tickvals] = ticks
|
|
||||||
# elseif ttype == :ticks_and_labels
|
|
||||||
# ax[:tickmode] = "array"
|
|
||||||
# ax[:tickvals], ax[:ticktext] = ticks
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
|
|
||||||
# ax
|
|
||||||
# else
|
|
||||||
# Dict(
|
|
||||||
# :showticklabels => false,
|
|
||||||
# :showgrid => false,
|
|
||||||
# )
|
|
||||||
# end)
|
|
||||||
|
|
||||||
|
|
||||||
# # y-axis
|
|
||||||
# d_out[:yaxis] = Dict(
|
|
||||||
# :title => d[:ylabel],
|
|
||||||
# :showgrid => d[:grid],
|
|
||||||
# :zeroline => false,
|
|
||||||
# )
|
|
||||||
# merge!(d_out[:yaxis], if use_axis_field(d[:yticks])
|
|
||||||
# Dict(
|
|
||||||
# :titlefont => plotlyfont(d[:guidefont]),
|
|
||||||
# :type => plotlyscale(d[:yscale]),
|
|
||||||
# :tickfont => plotlyfont(d[:tickfont]),
|
|
||||||
# :tickcolor => fgcolor,
|
|
||||||
# :linecolor => fgcolor,
|
|
||||||
# )
|
|
||||||
# else
|
|
||||||
# Dict(
|
|
||||||
# :showticklabels => false,
|
|
||||||
# :showgrid => false,
|
|
||||||
# )
|
|
||||||
# end)
|
|
||||||
|
|
||||||
# lims = d[:ylims]
|
|
||||||
# if lims != :auto && limsType(lims) == :limits
|
|
||||||
# d_out[:yaxis][:range] = lims
|
|
||||||
# end
|
|
||||||
|
|
||||||
# if d[:yflip]
|
|
||||||
# d_out[:yaxis][:autorange] = "reversed"
|
|
||||||
# end
|
|
||||||
|
|
||||||
# legend
|
# legend
|
||||||
d_out[:showlegend] = d[:legend]
|
d_out[:showlegend] = d[:legend]
|
||||||
if d[:legend]
|
if d[:legend]
|
||||||
@ -288,8 +211,11 @@ function get_plot_json(plt::Plot{PlotlyPackage})
|
|||||||
d_out[:annotations] = [get_annotation_dict(ann...) for ann in anns]
|
d_out[:annotations] = [get_annotation_dict(ann...) for ann in anns]
|
||||||
end
|
end
|
||||||
|
|
||||||
# finally build and return the json
|
d_out
|
||||||
JSON.json(d_out)
|
end
|
||||||
|
|
||||||
|
function get_plot_json(plt::Plot{PlotlyPackage})
|
||||||
|
JSON.json(plotly_layout(plt.plotargs))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -309,7 +235,7 @@ const _plotly_markers = Dict(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# get a dictionary representing the series params (d is the Plots-dict, d_out is the Plotly-dict)
|
# get a dictionary representing the series params (d is the Plots-dict, d_out is the Plotly-dict)
|
||||||
function get_series_json(d::Dict; plot_index = nothing)
|
function plotly_series(d::Dict; plot_index = nothing)
|
||||||
d_out = Dict()
|
d_out = Dict()
|
||||||
|
|
||||||
x, y = collect(d[:x]), collect(d[:y])
|
x, y = collect(d[:x]), collect(d[:y])
|
||||||
@ -366,7 +292,7 @@ function get_series_json(d::Dict; plot_index = nothing)
|
|||||||
d_out[:z] = d[:z].surf
|
d_out[:z] = d[:z].surf
|
||||||
# d_out[:showscale] = d[:legend]
|
# d_out[:showscale] = d[:legend]
|
||||||
if lt == :contour
|
if lt == :contour
|
||||||
d_out[:ncontours] = d[:nlevels]
|
d_out[:ncontours] = d[:levels]
|
||||||
d_out[:contours] = Dict(:coloring => d[:fillrange] != nothing ? "fill" : "lines")
|
d_out[:contours] = Dict(:coloring => d[:fillrange] != nothing ? "fill" : "lines")
|
||||||
end
|
end
|
||||||
d_out[:colorscale] = plotly_colorscale(d[lt == :contour ? :linecolor : :fillcolor])
|
d_out[:colorscale] = plotly_colorscale(d[lt == :contour ? :linecolor : :fillcolor])
|
||||||
@ -438,14 +364,14 @@ end
|
|||||||
|
|
||||||
# get a list of dictionaries, each representing the series params
|
# get a list of dictionaries, each representing the series params
|
||||||
function get_series_json(plt::Plot{PlotlyPackage})
|
function get_series_json(plt::Plot{PlotlyPackage})
|
||||||
JSON.json(map(get_series_json, plt.seriesargs))
|
JSON.json(map(plotly_series, plt.seriesargs))
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_series_json(subplt::Subplot{PlotlyPackage})
|
function get_series_json(subplt::Subplot{PlotlyPackage})
|
||||||
ds = Dict[]
|
ds = Dict[]
|
||||||
for (i,plt) in enumerate(subplt.plts)
|
for (i,plt) in enumerate(subplt.plts)
|
||||||
for d in plt.seriesargs
|
for d in plt.seriesargs
|
||||||
push!(ds, get_series_json(d, plot_index = i))
|
push!(ds, plotly_series(d, plot_index = i))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
JSON.json(ds)
|
JSON.json(ds)
|
||||||
|
|||||||
48
src/backends/plotly_blink.jl
Normal file
48
src/backends/plotly_blink.jl
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
|
||||||
|
# override some methods to use Plotlyjs/Blink
|
||||||
|
|
||||||
|
import Plotlyjs
|
||||||
|
|
||||||
|
function _create_plot(pkg::PlotlyPackage; 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
|
||||||
|
o = Plotlyjs.Plot()
|
||||||
|
|
||||||
|
Plot(o, pkg, 0, d, Dict[])
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function _add_series(::PlotlyPackage, plt::Plot; kw...)
|
||||||
|
d = Dict(kw)
|
||||||
|
|
||||||
|
# add to the data array
|
||||||
|
pdict = plotly_series(d)
|
||||||
|
gt = Plotlyjs.GenericTrace(pdict[:type], pdict)
|
||||||
|
push!(plt.o.data, gt)
|
||||||
|
if !isnull(plt.o.window)
|
||||||
|
Plotlyjs.addtraces!(plt.o, gt)
|
||||||
|
end
|
||||||
|
|
||||||
|
push!(plt.seriesargs, d)
|
||||||
|
plt
|
||||||
|
end
|
||||||
|
|
||||||
|
# TODO: override this to update plot items (title, xlabel, etc) after creation
|
||||||
|
function _update_plot(plt::Plot{PlotlyPackage}, d::Dict)
|
||||||
|
pdict = plotly_layout(d)
|
||||||
|
plt.o.layout = Plotlyjs.Layout(pdict)
|
||||||
|
if !isnull(plt.o.window)
|
||||||
|
Plotlyjs.relayout!(plt.o, pdict...)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function Base.display(::PlotsDisplay, plt::Plot{PlotlyPackage})
|
||||||
|
dump(plt.o)
|
||||||
|
show(plt.o)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Base.display(::PlotsDisplay, plt::Subplot{PlotlyPackage})
|
||||||
|
error()
|
||||||
|
end
|
||||||
@ -207,6 +207,10 @@ function _create_plot(pkg::PyPlotPackage; kw...)
|
|||||||
w,h = map(px2inch, d[:size])
|
w,h = map(px2inch, d[:size])
|
||||||
bgcolor = getPyPlotColor(d[:background_color])
|
bgcolor = getPyPlotColor(d[:background_color])
|
||||||
wrap = PyPlotAxisWrapper(nothing, nothing, PyPlot.figure(; figsize = (w,h), facecolor = bgcolor, dpi = DPI, tight_layout = true), [])
|
wrap = PyPlotAxisWrapper(nothing, nothing, PyPlot.figure(; figsize = (w,h), facecolor = bgcolor, dpi = DPI, tight_layout = true), [])
|
||||||
|
|
||||||
|
if haskey(d, :linetype) && first(d[:linetype]) in _3dTypes # && isa(plt.o, PyPlotFigWrapper)
|
||||||
|
push!(wrap.kwargs, (:projection, "3d"))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
plt = Plot(wrap, pkg, 0, d, Dict[])
|
plt = Plot(wrap, pkg, 0, d, Dict[])
|
||||||
@ -218,7 +222,7 @@ function _add_series(pkg::PyPlotPackage, plt::Plot; kw...)
|
|||||||
d = Dict(kw)
|
d = Dict(kw)
|
||||||
|
|
||||||
lt = d[:linetype]
|
lt = d[:linetype]
|
||||||
if lt in _3dTypes # && isa(plt.o, PyPlotFigWrapper)
|
if lt in _3dTypes && isempty(plt.o.kwargs)
|
||||||
push!(plt.o.kwargs, (:projection, "3d"))
|
push!(plt.o.kwargs, (:projection, "3d"))
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -232,7 +236,7 @@ function _add_series(pkg::PyPlotPackage, plt::Plot; kw...)
|
|||||||
|
|
||||||
if lt == :sticks
|
if lt == :sticks
|
||||||
d,_ = sticksHack(;d...)
|
d,_ = sticksHack(;d...)
|
||||||
|
|
||||||
elseif lt in (:scatter, :scatter3d)
|
elseif lt in (:scatter, :scatter3d)
|
||||||
if d[:markershape] == :none
|
if d[:markershape] == :none
|
||||||
d[:markershape] = :ellipse
|
d[:markershape] = :ellipse
|
||||||
@ -249,7 +253,7 @@ function _add_series(pkg::PyPlotPackage, plt::Plot; kw...)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
lt = d[:linetype]
|
# lt = d[:linetype]
|
||||||
extra_kwargs = Dict()
|
extra_kwargs = Dict()
|
||||||
|
|
||||||
plotfunc = getPyPlotFunction(plt, d[:axis], lt)
|
plotfunc = getPyPlotFunction(plt, d[:axis], lt)
|
||||||
@ -333,18 +337,35 @@ function _add_series(pkg::PyPlotPackage, plt::Plot; kw...)
|
|||||||
# do the plot
|
# do the plot
|
||||||
d[:serieshandle] = if ishistlike(lt)
|
d[:serieshandle] = if ishistlike(lt)
|
||||||
plotfunc(d[:y]; extra_kwargs...)[1]
|
plotfunc(d[:y]; extra_kwargs...)[1]
|
||||||
|
|
||||||
elseif lt == :contour
|
elseif lt == :contour
|
||||||
# NOTE: x/y are backwards in pyplot, so we switch the x and y args (also y is reversed),
|
|
||||||
# and take the transpose of the surface matrix
|
|
||||||
x, y = d[:x], d[:y]
|
x, y = d[:x], d[:y]
|
||||||
surf = d[:z].surf'
|
surf = d[:z].surf'
|
||||||
handle = plotfunc(x, y, surf, d[:nlevels]; extra_kwargs...)
|
levels = d[:levels]
|
||||||
|
if isscalar(levels)
|
||||||
|
extra_args = (levels)
|
||||||
|
elseif isvector(levels)
|
||||||
|
extra_args = ()
|
||||||
|
extra_kwargs[:levels] = levels
|
||||||
|
else
|
||||||
|
error("Only numbers and vectors are supported with levels keyword")
|
||||||
|
end
|
||||||
|
handle = plotfunc(x, y, surf, extra_args...; extra_kwargs...)
|
||||||
if d[:fillrange] != nothing
|
if d[:fillrange] != nothing
|
||||||
handle = ax[:contourf](x, y, surf, d[:nlevels]; cmap = getPyPlotColorMap(d[:fillcolor], d[:fillalpha]))
|
extra_kwargs[:cmap] = getPyPlotColorMap(d[:fillcolor], d[:fillalpha])
|
||||||
|
delete!(extra_kwargs, :linewidths)
|
||||||
|
handle = ax[:contourf](x, y, surf, extra_args...; extra_kwargs...)
|
||||||
end
|
end
|
||||||
handle
|
handle
|
||||||
|
|
||||||
elseif lt in (:surface,:wireframe)
|
elseif lt in (:surface,:wireframe)
|
||||||
plotfunc(repmat(d[:x]',length(d[:y]),1), repmat(d[:y],1,length(d[:x])), d[:z].surf'; extra_kwargs...)
|
x, y, z = d[:x], d[:y], Array(d[:z])
|
||||||
|
if !ismatrix(x) || !ismatrix(y)
|
||||||
|
x = repmat(x', length(y), 1)
|
||||||
|
y = repmat(y, 1, length(d[:x]))
|
||||||
|
z = z'
|
||||||
|
end
|
||||||
|
plotfunc(x, y, z; extra_kwargs...)
|
||||||
elseif lt in _3dTypes
|
elseif lt in _3dTypes
|
||||||
plotfunc(d[:x], d[:y], d[:z]; extra_kwargs...)
|
plotfunc(d[:x], d[:y], d[:z]; extra_kwargs...)
|
||||||
elseif lt in (:scatter, :heatmap, :hexbin)
|
elseif lt in (:scatter, :heatmap, :hexbin)
|
||||||
@ -465,7 +486,7 @@ function _update_plot(plt::Plot{PyPlotPackage}, d::Dict)
|
|||||||
ax[:set_ylabel](d[:ylabel])
|
ax[:set_ylabel](d[:ylabel])
|
||||||
end
|
end
|
||||||
if usingRightAxis(plt) && get(d, :yrightlabel, "") != ""
|
if usingRightAxis(plt) && get(d, :yrightlabel, "") != ""
|
||||||
rightax = getRightAxis(figorax)
|
rightax = getRightAxis(figorax)
|
||||||
rightax[:set_ylabel](d[:yrightlabel])
|
rightax[:set_ylabel](d[:yrightlabel])
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -494,7 +515,7 @@ function _update_plot(plt::Plot{PyPlotPackage}, d::Dict)
|
|||||||
# font sizes
|
# font sizes
|
||||||
for ax in axes
|
for ax in axes
|
||||||
# haskey(d, :yrightlabel) || continue
|
# haskey(d, :yrightlabel) || continue
|
||||||
|
|
||||||
|
|
||||||
# guides
|
# guides
|
||||||
sz = get(d, :guidefont, plt.plotargs[:guidefont]).pointsize
|
sz = get(d, :guidefont, plt.plotargs[:guidefont]).pointsize
|
||||||
@ -509,7 +530,7 @@ function _update_plot(plt::Plot{PyPlotPackage}, d::Dict)
|
|||||||
lab[:set_fontsize](sz)
|
lab[:set_fontsize](sz)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# grid
|
# grid
|
||||||
if get(d, :grid, false)
|
if get(d, :grid, false)
|
||||||
ax[:xaxis][:grid](true)
|
ax[:xaxis][:grid](true)
|
||||||
@ -629,7 +650,7 @@ end
|
|||||||
function addPyPlotLegend(plt::Plot, ax)
|
function addPyPlotLegend(plt::Plot, ax)
|
||||||
if plt.plotargs[:legend]
|
if plt.plotargs[:legend]
|
||||||
# gotta do this to ensure both axes are included
|
# gotta do this to ensure both axes are included
|
||||||
args = filter(x -> !(x[:linetype] in (:hist,:density,:hexbin,:heatmap,:hline,:vline,:contour, :path3d, :scatter3d)), plt.seriesargs)
|
args = filter(x -> !(x[:linetype] in (:hist,:density,:hexbin,:heatmap,:hline,:vline,:contour, :surface, :wireframe, :path3d, :scatter3d)), plt.seriesargs)
|
||||||
if length(args) > 0
|
if length(args) > 0
|
||||||
leg = ax[:legend]([d[:serieshandle] for d in args],
|
leg = ax[:legend]([d[:serieshandle] for d in args],
|
||||||
[d[:label] for d in args],
|
[d[:label] for d in args],
|
||||||
|
|||||||
@ -74,10 +74,10 @@ supportedArgs(::GadflyPackage) = [
|
|||||||
:legendfont,
|
:legendfont,
|
||||||
:grid,
|
:grid,
|
||||||
# :surface,
|
# :surface,
|
||||||
:nlevels,
|
:levels,
|
||||||
]
|
]
|
||||||
supportedAxes(::GadflyPackage) = [:auto, :left]
|
supportedAxes(::GadflyPackage) = [:auto, :left]
|
||||||
supportedTypes(::GadflyPackage) = [:none, :line, :path, :steppre, :steppost, :sticks,
|
supportedTypes(::GadflyPackage) = [:none, :line, :path, :steppre, :steppost, :sticks,
|
||||||
:scatter, :heatmap, :hexbin, :hist, :bar,
|
:scatter, :heatmap, :hexbin, :hist, :bar,
|
||||||
:hline, :vline, :contour]
|
:hline, :vline, :contour]
|
||||||
supportedStyles(::GadflyPackage) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
|
supportedStyles(::GadflyPackage) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
|
||||||
@ -154,13 +154,13 @@ supportedArgs(::PyPlotPackage) = [
|
|||||||
:legendfont,
|
:legendfont,
|
||||||
:grid,
|
:grid,
|
||||||
# :surface,
|
# :surface,
|
||||||
:nlevels,
|
:levels,
|
||||||
:fillalpha,
|
:fillalpha,
|
||||||
:linealpha,
|
:linealpha,
|
||||||
:markeralpha,
|
:markeralpha,
|
||||||
]
|
]
|
||||||
supportedAxes(::PyPlotPackage) = _allAxes
|
supportedAxes(::PyPlotPackage) = _allAxes
|
||||||
supportedTypes(::PyPlotPackage) = [:none, :line, :path, :steppre, :steppost, :sticks,
|
supportedTypes(::PyPlotPackage) = [:none, :line, :path, :steppre, :steppost, #:sticks,
|
||||||
:scatter, :heatmap, :hexbin, :hist, :density, :bar,
|
:scatter, :heatmap, :hexbin, :hist, :density, :bar,
|
||||||
:hline, :vline, :contour, :path3d, :scatter3d, :surface, :wireframe]
|
:hline, :vline, :contour, :path3d, :scatter3d, :surface, :wireframe]
|
||||||
supportedStyles(::PyPlotPackage) = [:auto, :solid, :dash, :dot, :dashdot]
|
supportedStyles(::PyPlotPackage) = [:auto, :solid, :dash, :dot, :dashdot]
|
||||||
@ -413,7 +413,7 @@ supportedArgs(::BokehPackage) = [
|
|||||||
# :legendfont,
|
# :legendfont,
|
||||||
# :grid,
|
# :grid,
|
||||||
# :surface,
|
# :surface,
|
||||||
# :nlevels,
|
# :levels,
|
||||||
]
|
]
|
||||||
supportedAxes(::BokehPackage) = [:auto, :left]
|
supportedAxes(::BokehPackage) = [:auto, :left]
|
||||||
supportedTypes(::BokehPackage) = [:none, :path, :scatter] #,:steppre, :steppost, :sticks, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :contour]
|
supportedTypes(::BokehPackage) = [:none, :path, :scatter] #,:steppre, :steppost, :sticks, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :contour]
|
||||||
@ -479,7 +479,7 @@ supportedArgs(::PlotlyPackage) = [
|
|||||||
:guidefont,
|
:guidefont,
|
||||||
:legendfont,
|
:legendfont,
|
||||||
:grid,
|
:grid,
|
||||||
:nlevels,
|
:levels,
|
||||||
]
|
]
|
||||||
supportedAxes(::PlotlyPackage) = [:auto, :left]
|
supportedAxes(::PlotlyPackage) = [:auto, :left]
|
||||||
supportedTypes(::PlotlyPackage) = [:none, :line, :path, :scatter, :steppre, :steppost,
|
supportedTypes(::PlotlyPackage) = [:none, :line, :path, :scatter, :steppre, :steppost,
|
||||||
@ -492,3 +492,68 @@ supportedScales(::PlotlyPackage) = [:identity, :log10] #, :ln, :log2, :log10, :a
|
|||||||
subplotSupported(::PlotlyPackage) = true
|
subplotSupported(::PlotlyPackage) = true
|
||||||
stringsSupported(::PlotlyPackage) = true
|
stringsSupported(::PlotlyPackage) = true
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
supportedArgs(::GLVisualizePackage) = [
|
||||||
|
# :annotation,
|
||||||
|
# :axis,
|
||||||
|
# :background_color,
|
||||||
|
# :color_palette,
|
||||||
|
# :fillrange,
|
||||||
|
# :fillcolor,
|
||||||
|
# :fillalpha,
|
||||||
|
# :foreground_color,
|
||||||
|
# :group,
|
||||||
|
# :label,
|
||||||
|
# :layout,
|
||||||
|
# :legend,
|
||||||
|
# :linecolor,
|
||||||
|
# :linestyle,
|
||||||
|
# :linetype,
|
||||||
|
# :linewidth,
|
||||||
|
# :linealpha,
|
||||||
|
# :markershape,
|
||||||
|
# :markercolor,
|
||||||
|
# :markersize,
|
||||||
|
# :markeralpha,
|
||||||
|
# :markerstrokewidth,
|
||||||
|
# :markerstrokecolor,
|
||||||
|
# :markerstrokestyle,
|
||||||
|
# :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,
|
||||||
|
# :surface
|
||||||
|
# :levels,
|
||||||
|
]
|
||||||
|
supportedAxes(::GLVisualizePackage) = [:auto, :left]
|
||||||
|
supportedTypes(::GLVisualizePackage) = [:contour] #, :path, :scatter ,:steppre, :steppost, :sticks, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :contour]
|
||||||
|
supportedStyles(::GLVisualizePackage) = [:auto, :solid] #, :dash, :dot, :dashdot, :dashdotdot]
|
||||||
|
supportedMarkers(::GLVisualizePackage) = [:none, :auto, :ellipse] #, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5] #vcat(_allMarkers, Shape)
|
||||||
|
supportedScales(::GLVisualizePackage) = [:identity] #, :log, :log2, :log10, :asinh, :sqrt]
|
||||||
|
subplotSupported(::GLVisualizePackage) = false
|
||||||
|
|||||||
@ -231,6 +231,8 @@ end
|
|||||||
|
|
||||||
Surface(f::Function, x, y) = Surface(Float64[f(xi,yi) for xi in x, yi in y])
|
Surface(f::Function, x, y) = Surface(Float64[f(xi,yi) for xi in x, yi in y])
|
||||||
|
|
||||||
|
Base.Array(surf::Surface) = surf.surf
|
||||||
|
|
||||||
# -----------------------------------------------------------------------
|
# -----------------------------------------------------------------------
|
||||||
|
|
||||||
type OHLC{T<:Real}
|
type OHLC{T<:Real}
|
||||||
|
|||||||
@ -37,6 +37,15 @@ end
|
|||||||
ps(fn::@compat(AbstractString)) = ps(current(), fn)
|
ps(fn::@compat(AbstractString)) = ps(current(), fn)
|
||||||
|
|
||||||
|
|
||||||
|
function tex(plt::PlottingObject, fn::@compat(AbstractString))
|
||||||
|
fn = addExtension(fn, "tex")
|
||||||
|
io = open(fn, "w")
|
||||||
|
writemime(io, MIME("application/x-tex"), plt)
|
||||||
|
close(io)
|
||||||
|
end
|
||||||
|
tex(fn::@compat(AbstractString)) = tex(current(), fn)
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
@ -45,6 +54,7 @@ ps(fn::@compat(AbstractString)) = ps(current(), fn)
|
|||||||
"svg" => svg,
|
"svg" => svg,
|
||||||
"pdf" => pdf,
|
"pdf" => pdf,
|
||||||
"ps" => ps,
|
"ps" => ps,
|
||||||
|
"tex" => tex,
|
||||||
)
|
)
|
||||||
|
|
||||||
function getExtension(fn::@compat(AbstractString))
|
function getExtension(fn::@compat(AbstractString))
|
||||||
|
|||||||
25
src/plot.jl
25
src/plot.jl
@ -48,7 +48,7 @@ function plot(args...; kw...)
|
|||||||
preprocessArgs!(d)
|
preprocessArgs!(d)
|
||||||
dumpdict(d, "After plot preprocessing")
|
dumpdict(d, "After plot preprocessing")
|
||||||
|
|
||||||
plotargs = getPlotArgs(pkg, d, 1)
|
plotargs = merge(d, getPlotArgs(pkg, d, 1))
|
||||||
dumpdict(plotargs, "Plot args")
|
dumpdict(plotargs, "Plot args")
|
||||||
plt = _create_plot(pkg; plotargs...) # create a new, blank plot
|
plt = _create_plot(pkg; plotargs...) # create a new, blank plot
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ function plot!(plt::Plot, args...; kw...)
|
|||||||
|
|
||||||
# get the list of dictionaries, one per series
|
# get the list of dictionaries, one per series
|
||||||
seriesArgList, xmeta, ymeta = createKWargsList(plt, groupargs..., args...; d...)
|
seriesArgList, xmeta, ymeta = createKWargsList(plt, groupargs..., args...; d...)
|
||||||
|
|
||||||
# if we were able to extract guide information from the series inputs, then update the plot
|
# if we were able to extract guide information from the series inputs, then update the plot
|
||||||
# @show xmeta, ymeta
|
# @show xmeta, ymeta
|
||||||
updateDictWithMeta(d, plt.plotargs, xmeta, true)
|
updateDictWithMeta(d, plt.plotargs, xmeta, true)
|
||||||
@ -378,16 +378,32 @@ function createKWargsList{T<:Real}(plt::PlottingObject, x::AVec, y::AVec, zmat::
|
|||||||
@assert x == sort(x)
|
@assert x == sort(x)
|
||||||
@assert y == sort(y)
|
@assert y == sort(y)
|
||||||
@assert size(zmat) == (length(x), length(y))
|
@assert size(zmat) == (length(x), length(y))
|
||||||
|
# surf = Surface(convert(Matrix{Float64}, zmat))
|
||||||
|
# surf = Array(Any,1,1)
|
||||||
|
# surf[1,1] = convert(Matrix{Float64}, zmat)
|
||||||
|
d = Dict(kw)
|
||||||
|
d[:z] = Surface(convert(Matrix{Float64}, zmat))
|
||||||
|
if !(get(d, :linetype, :none) in (:contour, :surface, :wireframe))
|
||||||
|
d[:linetype] = :contour
|
||||||
|
end
|
||||||
|
createKWargsList(plt, x, y; d...) #, z = surf)
|
||||||
|
end
|
||||||
|
|
||||||
|
# contours or surfaces... general x, y grid
|
||||||
|
function createKWargsList{T<:Real}(plt::PlottingObject, x::AMat{T}, y::AMat{T}, zmat::AMat{T}; kw...)
|
||||||
|
@assert size(zmat) == size(x) == size(y)
|
||||||
surf = Surface(convert(Matrix{Float64}, zmat))
|
surf = Surface(convert(Matrix{Float64}, zmat))
|
||||||
# surf = Array(Any,1,1)
|
# surf = Array(Any,1,1)
|
||||||
# surf[1,1] = convert(Matrix{Float64}, zmat)
|
# surf[1,1] = convert(Matrix{Float64}, zmat)
|
||||||
d = Dict(kw)
|
d = Dict(kw)
|
||||||
|
d[:z] = Surface(convert(Matrix{Float64}, zmat))
|
||||||
if !(get(d, :linetype, :none) in (:contour, :surface, :wireframe))
|
if !(get(d, :linetype, :none) in (:contour, :surface, :wireframe))
|
||||||
d[:linetype] = :contour
|
d[:linetype] = :contour
|
||||||
end
|
end
|
||||||
createKWargsList(plt, x, y; d..., z = surf)
|
createKWargsList(plt, Any[x], Any[y]; d...) #kw..., z = surf, linetype = :contour)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function createKWargsList(plt::PlottingObject, surf::Surface; kw...)
|
function createKWargsList(plt::PlottingObject, surf::Surface; kw...)
|
||||||
createKWargsList(plt, 1:size(surf.surf,1), 1:size(surf.surf,2), convert(Matrix{Float64}, surf.surf); kw...)
|
createKWargsList(plt, 1:size(surf.surf,1), 1:size(surf.surf,2), convert(Matrix{Float64}, surf.surf); kw...)
|
||||||
end
|
end
|
||||||
@ -431,7 +447,7 @@ function createKWargsList(plt::PlottingObject; kw...)
|
|||||||
return [], nothing, nothing
|
return [], nothing, nothing
|
||||||
# error("Called plot/subplot without args... must set y in the keyword args. Example: plot(; y=rand(10))")
|
# error("Called plot/subplot without args... must set y in the keyword args. Example: plot(; y=rand(10))")
|
||||||
end
|
end
|
||||||
|
|
||||||
if haskey(d, :x)
|
if haskey(d, :x)
|
||||||
return createKWargsList(plt, d[:x], d[:y]; kw...)
|
return createKWargsList(plt, d[:x], d[:y]; kw...)
|
||||||
else
|
else
|
||||||
@ -474,4 +490,3 @@ end
|
|||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,7 @@ immutable UnicodePlotsPackage <: PlottingPackage end
|
|||||||
immutable WinstonPackage <: PlottingPackage end
|
immutable WinstonPackage <: PlottingPackage end
|
||||||
immutable BokehPackage <: PlottingPackage end
|
immutable BokehPackage <: PlottingPackage end
|
||||||
immutable PlotlyPackage <: PlottingPackage end
|
immutable PlotlyPackage <: PlottingPackage end
|
||||||
|
immutable GLVisualizePackage <: PlottingPackage end
|
||||||
immutable NoPackage <: PlottingPackage end
|
immutable NoPackage <: PlottingPackage end
|
||||||
|
|
||||||
typealias GadflyOrImmerse @compat(Union{GadflyPackage, ImmersePackage})
|
typealias GadflyOrImmerse @compat(Union{GadflyPackage, ImmersePackage})
|
||||||
@ -19,7 +20,8 @@ export
|
|||||||
qwt,
|
qwt,
|
||||||
unicodeplots,
|
unicodeplots,
|
||||||
bokeh,
|
bokeh,
|
||||||
plotly
|
plotly,
|
||||||
|
glvisualize
|
||||||
# winston
|
# winston
|
||||||
|
|
||||||
gadfly() = backend(:gadfly)
|
gadfly() = backend(:gadfly)
|
||||||
@ -29,6 +31,7 @@ qwt() = backend(:qwt)
|
|||||||
unicodeplots() = backend(:unicodeplots)
|
unicodeplots() = backend(:unicodeplots)
|
||||||
bokeh() = backend(:bokeh)
|
bokeh() = backend(:bokeh)
|
||||||
plotly() = backend(:plotly)
|
plotly() = backend(:plotly)
|
||||||
|
glvisualize() = backend(:glvisualize)
|
||||||
# winston() = backend(:winston)
|
# winston() = backend(:winston)
|
||||||
|
|
||||||
backend_name(::GadflyPackage) = :gadfly
|
backend_name(::GadflyPackage) = :gadfly
|
||||||
@ -38,6 +41,7 @@ backend_name(::UnicodePlotsPackage) = :unicodeplots
|
|||||||
backend_name(::QwtPackage) = :qwt
|
backend_name(::QwtPackage) = :qwt
|
||||||
backend_name(::BokehPackage) = :bokeh
|
backend_name(::BokehPackage) = :bokeh
|
||||||
backend_name(::PlotlyPackage) = :plotly
|
backend_name(::PlotlyPackage) = :plotly
|
||||||
|
backend_name(::GLVisualizePackage) = :glvisualize
|
||||||
backend_name(::NoPackage) = :none
|
backend_name(::NoPackage) = :none
|
||||||
|
|
||||||
include("backends/supported.jl")
|
include("backends/supported.jl")
|
||||||
@ -53,6 +57,8 @@ include("backends/web.jl")
|
|||||||
include("backends/bokeh.jl")
|
include("backends/bokeh.jl")
|
||||||
include("backends/plotly.jl")
|
include("backends/plotly.jl")
|
||||||
|
|
||||||
|
include("backends/glvisualize.jl")
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
@ -85,9 +91,10 @@ function backendInstance(sym::Symbol)
|
|||||||
sym == :winston && return WinstonPackage()
|
sym == :winston && return WinstonPackage()
|
||||||
sym == :bokeh && return BokehPackage()
|
sym == :bokeh && return BokehPackage()
|
||||||
sym == :plotly && return PlotlyPackage()
|
sym == :plotly && return PlotlyPackage()
|
||||||
|
sym == :glvisualize && return GLVisualizePackage()
|
||||||
sym == :none && return NoPackage()
|
sym == :none && return NoPackage()
|
||||||
error("Unsupported backend $sym")
|
error("Unsupported backend $sym")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
type CurrentBackend
|
type CurrentBackend
|
||||||
@ -99,7 +106,7 @@ CurrentBackend(sym::Symbol) = CurrentBackend(sym, backendInstance(sym))
|
|||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
function pickDefaultBackend()
|
function pickDefaultBackend()
|
||||||
for pkgstr in ("PyPlot", "Immerse", "Qwt", "Gadfly", "UnicodePlots", "Bokeh")
|
for pkgstr in ("PyPlot", "Immerse", "Qwt", "Gadfly", "UnicodePlots", "Bokeh", "GLVisualize")
|
||||||
if Pkg.installed(pkgstr) != nothing
|
if Pkg.installed(pkgstr) != nothing
|
||||||
return backend(symbol(lowercase(pkgstr)))
|
return backend(symbol(lowercase(pkgstr)))
|
||||||
end
|
end
|
||||||
@ -163,7 +170,7 @@ function backend()
|
|||||||
# @eval const pycolorbar = PyPlot.pywrap(PyPlot.pyimport("matplotlib.colorbar"))
|
# @eval const pycolorbar = PyPlot.pywrap(PyPlot.pyimport("matplotlib.colorbar"))
|
||||||
if !isa(Base.Multimedia.displays[end], Base.REPL.REPLDisplay)
|
if !isa(Base.Multimedia.displays[end], Base.REPL.REPLDisplay)
|
||||||
PyPlot.ioff() # stops wierd behavior of displaying incomplete graphs in IJulia
|
PyPlot.ioff() # stops wierd behavior of displaying incomplete graphs in IJulia
|
||||||
|
|
||||||
# # TODO: how the hell can I use PyQt4??
|
# # TODO: how the hell can I use PyQt4??
|
||||||
# "pyqt4"=>:qt_pyqt4
|
# "pyqt4"=>:qt_pyqt4
|
||||||
# PyPlot.backend[1] = "pyqt4"
|
# PyPlot.backend[1] = "pyqt4"
|
||||||
@ -228,12 +235,27 @@ function backend()
|
|||||||
# end borrowing (thanks :)
|
# end borrowing (thanks :)
|
||||||
###########################
|
###########################
|
||||||
|
|
||||||
|
# try
|
||||||
|
# include(joinpath(Pkg.dir("Plots"), "src", "backends", "plotly_blink.jl"))
|
||||||
|
# catch err
|
||||||
|
# warn("Error including Plotlyjs: $err\n Note: Will fall back to built-in display.")
|
||||||
|
# end
|
||||||
|
|
||||||
end
|
end
|
||||||
catch err
|
catch err
|
||||||
warn("Couldn't setup Plotly")
|
warn("Couldn't setup Plotly")
|
||||||
rethrow(err)
|
rethrow(err)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
elseif currentBackendSymbol == :glvisualize
|
||||||
|
try
|
||||||
|
@eval import GLVisualize
|
||||||
|
@eval export GLVisualize
|
||||||
|
catch err
|
||||||
|
warn("Couldn't setup GLVisualize")
|
||||||
|
rethrow(err)
|
||||||
|
end
|
||||||
|
|
||||||
elseif currentBackendSymbol == :winston
|
elseif currentBackendSymbol == :winston
|
||||||
warn("Winston support is deprecated and broken. Try another backend: $BACKENDS")
|
warn("Winston support is deprecated and broken. Try another backend: $BACKENDS")
|
||||||
try
|
try
|
||||||
@ -263,7 +285,7 @@ function backend(pkg::PlottingPackage)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function backend(modname)
|
function backend(modname)
|
||||||
|
|
||||||
# set the PlottingPackage
|
# set the PlottingPackage
|
||||||
if modname == :qwt
|
if modname == :qwt
|
||||||
CURRENT_BACKEND.pkg = QwtPackage()
|
CURRENT_BACKEND.pkg = QwtPackage()
|
||||||
@ -281,6 +303,8 @@ function backend(modname)
|
|||||||
CURRENT_BACKEND.pkg = BokehPackage()
|
CURRENT_BACKEND.pkg = BokehPackage()
|
||||||
elseif modname == :plotly
|
elseif modname == :plotly
|
||||||
CURRENT_BACKEND.pkg = PlotlyPackage()
|
CURRENT_BACKEND.pkg = PlotlyPackage()
|
||||||
|
elseif modname == :glvisualize
|
||||||
|
CURRENT_BACKEND.pkg = GLVisualizePackage()
|
||||||
else
|
else
|
||||||
error("Unknown backend $modname. Choose from: $BACKENDS")
|
error("Unknown backend $modname. Choose from: $BACKENDS")
|
||||||
end
|
end
|
||||||
|
|||||||
16
src/utils.jl
16
src/utils.jl
@ -174,7 +174,9 @@ function replaceAliases!(d::Dict, aliases::Dict)
|
|||||||
end
|
end
|
||||||
|
|
||||||
createSegments(z) = collect(repmat(z',2,1))[2:end]
|
createSegments(z) = collect(repmat(z',2,1))[2:end]
|
||||||
|
|
||||||
Base.first(c::Colorant) = c
|
Base.first(c::Colorant) = c
|
||||||
|
Base.first(x::Symbol) = x
|
||||||
|
|
||||||
|
|
||||||
sortedkeys(d::Dict) = sort(collect(keys(d)))
|
sortedkeys(d::Dict) = sort(collect(keys(d)))
|
||||||
@ -190,6 +192,17 @@ end
|
|||||||
|
|
||||||
isijulia() = isdefined(Main, :IJulia) && Main.IJulia.inited
|
isijulia() = isdefined(Main, :IJulia) && Main.IJulia.inited
|
||||||
|
|
||||||
|
istuple(::Tuple) = true
|
||||||
|
istuple(::Any) = false
|
||||||
|
isvector(::AVec) = true
|
||||||
|
isvector(::Any) = false
|
||||||
|
ismatrix(::AMat) = true
|
||||||
|
ismatrix(::Any) = false
|
||||||
|
isscalar(::Real) = true
|
||||||
|
isscalar(::Any) = false
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ticksType{T<:Real,S<:Real}(ticks::@compat(Tuple{T,S})) = :limits
|
# ticksType{T<:Real,S<:Real}(ticks::@compat(Tuple{T,S})) = :limits
|
||||||
ticksType{T<:Real}(ticks::AVec{T}) = :ticks
|
ticksType{T<:Real}(ticks::AVec{T}) = :ticks
|
||||||
@ -226,6 +239,9 @@ function with(f::Function, args...; kw...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# save the backend
|
# save the backend
|
||||||
|
if CURRENT_BACKEND.sym == :none
|
||||||
|
pickDefaultBackend()
|
||||||
|
end
|
||||||
oldbackend = CURRENT_BACKEND.sym
|
oldbackend = CURRENT_BACKEND.sym
|
||||||
|
|
||||||
for arg in args
|
for arg in args
|
||||||
|
|||||||
@ -73,7 +73,7 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = is
|
|||||||
|
|
||||||
# first
|
# first
|
||||||
Plots._debugMode.on = debug
|
Plots._debugMode.on = debug
|
||||||
example = ExamplePlots.examples[idx]
|
example = ExamplePlots._examples[idx]
|
||||||
info("Testing plot: $pkg:$idx:$(example.header)")
|
info("Testing plot: $pkg:$idx:$(example.header)")
|
||||||
backend(pkg)
|
backend(pkg)
|
||||||
backend()
|
backend()
|
||||||
@ -88,7 +88,7 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = is
|
|||||||
end
|
end
|
||||||
|
|
||||||
# run the example
|
# run the example
|
||||||
# map(eval, PlotExamples.examples[idx].exprs)
|
# map(eval, PlotExamples._examples[idx].exprs)
|
||||||
|
|
||||||
# # save the png
|
# # save the png
|
||||||
# tmpfn = tempname() * ".png"
|
# tmpfn = tempname() * ".png"
|
||||||
@ -148,7 +148,7 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = is
|
|||||||
end
|
end
|
||||||
|
|
||||||
function image_comparison_facts(pkg::Symbol; skip = [], debug = false, sigma = [1,1], eps = 1e-2)
|
function image_comparison_facts(pkg::Symbol; skip = [], debug = false, sigma = [1,1], eps = 1e-2)
|
||||||
for i in 1:length(ExamplePlots.examples)
|
for i in 1:length(ExamplePlots._examples)
|
||||||
i in skip && continue
|
i in skip && continue
|
||||||
@fact image_comparison_tests(pkg, i, debug=debug, sigma=sigma, eps=eps) |> success --> true
|
@fact image_comparison_tests(pkg, i, debug=debug, sigma=sigma, eps=eps) |> success --> true
|
||||||
end
|
end
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 114 KiB After Width: | Height: | Size: 116 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 42 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 39 KiB |
@ -30,7 +30,7 @@ default(show=false)
|
|||||||
# gadfly()
|
# gadfly()
|
||||||
# backend()
|
# backend()
|
||||||
|
|
||||||
img_eps = 2e-2
|
img_eps = 5e-2
|
||||||
|
|
||||||
facts("Gadfly") do
|
facts("Gadfly") do
|
||||||
@fact gadfly() --> Plots.GadflyPackage()
|
@fact gadfly() --> Plots.GadflyPackage()
|
||||||
@ -49,14 +49,14 @@ facts("Gadfly") do
|
|||||||
# plot(x::AMat, y::AMat; kw...) # multiple lines (one per column of x/y... will assert size(x) == size(y))
|
# plot(x::AMat, y::AMat; kw...) # multiple lines (one per column of x/y... will assert size(x) == size(y))
|
||||||
@fact plot!(rand(10,3), rand(10,3)) --> not(nothing)
|
@fact plot!(rand(10,3), rand(10,3)) --> not(nothing)
|
||||||
|
|
||||||
image_comparison_facts(:gadfly, skip=[4,19,23,24], eps=img_eps)
|
image_comparison_facts(:gadfly, skip=[4,6,19,23,24], eps=img_eps)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
facts("PyPlot") do
|
facts("PyPlot") do
|
||||||
@fact pyplot() --> Plots.PyPlotPackage()
|
@fact pyplot() --> Plots.PyPlotPackage()
|
||||||
@fact backend() --> Plots.PyPlotPackage()
|
@fact backend() --> Plots.PyPlotPackage()
|
||||||
image_comparison_facts(:pyplot, skip=[19,21,23], eps=img_eps)
|
image_comparison_facts(:pyplot, skip=[10,19,21,23], eps=img_eps)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user