immerse subplot gui fix; pyplot colorbars; subplot creation fix

This commit is contained in:
Thomas Breloff 2015-10-23 13:26:34 -04:00
parent 8d490b9e52
commit 479ab989df
6 changed files with 5230 additions and 38280 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -54,7 +54,7 @@ end
function addAnnotations{X,Y,V}(plt::Plot{ImmersePackage}, anns::AVec{@compat(Tuple{X,Y,V})})
for ann in anns
push!(plt.o[2].guides, createGadflyAnnotationObject(ann...))
push!(getGadflyContext(plt).guides, createGadflyAnnotationObject(ann...))
end
end
@ -62,17 +62,6 @@ end
# accessors for x/y data
# function Base.getindex(plt::Plot{ImmersePackage}, i::Int)
# data = plt.o[2].layers[end-i+1].mapping
# data[:x], data[:y]
# end
# function Base.setindex!(plt::Plot{ImmersePackage}, xy::Tuple, i::Integer)
# data = plt.o[2].layers[end-i+1].mapping
# data[:x], data[:y] = xy
# plt
# end
function Base.getindex(plt::Plot{ImmersePackage}, i::Integer)
mapping = getGadflyMappings(plt, i)[1]
mapping[:x], mapping[:y]
@ -80,9 +69,7 @@ end
function Base.setindex!(plt::Plot{ImmersePackage}, xy::Tuple, i::Integer)
for mapping in getGadflyMappings(plt, i)
# @show "before",i xy mapping[:x] mapping[:y]
mapping[:x], mapping[:y] = xy
# @show "after",i xy mapping[:x] mapping[:y]
end
plt
end
@ -92,8 +79,11 @@ end
function buildSubplotObject!(subplt::Subplot{ImmersePackage}, isbefore::Bool)
isbefore && return false
return false
# isbefore && return false
end
function showSubplotObject(subplt::Subplot{ImmersePackage})
# create the Gtk window with vertical box vsep
d = getinitargs(subplt,1)
w,h = d[:size]
@ -128,7 +118,7 @@ function buildSubplotObject!(subplt::Subplot{ImmersePackage}, isbefore::Bool)
end
# destructor... clean up plots
Gtk.on_signal_destroy((x...) -> [Immerse.dropfig(Immerse._display,i) for i in figindices], win)
Gtk.on_signal_destroy((x...) -> ([Immerse.dropfig(Immerse._display,i) for i in figindices]; subplt.o = nothing), win)
subplt.o = win
true
@ -194,6 +184,11 @@ end
function Base.display(::PlotsDisplay, subplt::Subplot{ImmersePackage})
# if we haven't created the window yet, do it
if subplt.o == nothing
showSubplotObject(subplt)
end
# display the plots by creating a fresh Immerse.Figure object from the GtkCanvas and Gadfly.Plot
for plt in subplt.plts
fig, gplt = plt.o

View File

@ -1,73 +1,8 @@
# https://github.com/stevengj/PyPlot.jl
# immutable PyPlotPackage <: PlottingPackage end
# export pyplot
# pyplot() = backend(:pyplot)
# -------------------------------
# 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))
getPyPlotColor(scheme::ColorScheme) = getPyPlotColor(getColor(scheme))
@ -88,12 +23,6 @@ function getPyPlotLineStyle(linetype::Symbol, linestyle::Symbol)
return "-"
end
# function getMarkerGeom(d::Dict)
# shape = d[:markershape]
# gadflyshape(isa(shape, Shape) ? shape : _shapes[shape])
# end
function getPyPlotMarker(marker::Shape)
marker.vertices
end
@ -277,6 +206,12 @@ function plot!(pkg::PyPlotPackage, plt::Plot; kw...)
elseif lt in (:heatmap, :hexbin)
extraargs[:gridsize] = d[:nbins]
c = d[:color]
if !isa(c, ColorGradient)
c = ColorGradient(:redsblues)
end
# c = ColorGradient(d[:color])
extraargs[:cmap] = getPyPlotColorMap(c)
else
@ -307,12 +242,17 @@ function plot!(pkg::PyPlotPackage, plt::Plot; kw...)
extraargs[:label] = d[:label]
# do the plot
if lt == :hist
d[:serieshandle] = plotfunc(d[:y]; extraargs...)[1]
d[:serieshandle] = if lt == :hist
plotfunc(d[:y]; extraargs...)[1]
elseif lt in (:scatter, :heatmap, :hexbin)
d[:serieshandle] = plotfunc(d[:x], d[:y]; extraargs...)
plotfunc(d[:x], d[:y]; extraargs...)
else
d[:serieshandle] = plotfunc(d[:x], d[:y]; extraargs...)[1]
plotfunc(d[:x], d[:y]; extraargs...)[1]
end
# add the colorbar legend
if plt.initargs[:legend] && haskey(extraargs, :cmap)
PyPlot.colorbar(d[:serieshandle])
end
# this sets the bg color inside the grid

View File

@ -157,6 +157,7 @@ function backend()
@eval import PyPlot
@eval export PyPlot
@eval const pycolors = PyPlot.pywrap(PyPlot.pyimport("matplotlib.colors"))
# @eval const pycolorbar = PyPlot.pywrap(PyPlot.pyimport("matplotlib.colorbar"))
if !isa(Base.Multimedia.displays[end], Base.REPL.REPLDisplay)
PyPlot.ioff()
end

View File

@ -170,7 +170,7 @@ function subplot(args...; kw...)
# initialize the individual plots
pkg = backend()
plts = Plot[]
plts = Plot{typeof(pkg)}[]
# ds = Dict[]
for i in 1:length(layout)
di = getPlotArgs(pkg, d, i)