working on pyplot
This commit is contained in:
parent
c052e731f8
commit
e38820b74a
File diff suppressed because one or more lines are too long
@ -116,16 +116,32 @@ function getPyPlotDrawStyle(linetype::Symbol)
|
|||||||
return "default"
|
return "default"
|
||||||
end
|
end
|
||||||
|
|
||||||
# get a reference to the right axis
|
|
||||||
getLeftAxis(o) = o.o[:axes][1]
|
type PyPlotFigWrapper
|
||||||
getRightAxis(o) = getLeftAxis(o)[:twinx]()
|
fig
|
||||||
|
end
|
||||||
|
|
||||||
|
type PyPlotAxisWrapper
|
||||||
|
ax
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# get a reference to the correct axis
|
||||||
|
getLeftAxis(fig::PyPlotFigWrapper) = fig.o[:axes][1]
|
||||||
|
getLeftAxis(ax::PyPlotAxisWrapper) = ax
|
||||||
|
getLeftAxis(plt::Plot{PyPlotPackage}) = getLeftAxis(plt.o)
|
||||||
|
getRightAxis(x) = getLeftAxis(x)[:twinx]()
|
||||||
|
getAxis(plt::Plot{PyPlotPackage}, axis::Symbol) = (axis == :right ? getRightAxis : getLeftAxis)(plt)
|
||||||
|
|
||||||
# left axis is PyPlot.<func>, right axis is "f.axes[0].twinx().<func>"
|
# left axis is PyPlot.<func>, right axis is "f.axes[0].twinx().<func>"
|
||||||
function getPyPlotFunction(plt::Plot, axis::Symbol, linetype::Symbol)
|
function getPyPlotFunction(plt::Plot, axis::Symbol, linetype::Symbol)
|
||||||
|
|
||||||
# in the 2-axis case we need to get: <rightaxis>[:<func>]
|
# in the 2-axis case we need to get: <rightaxis>[:<func>]
|
||||||
if axis == :right
|
ax = getAxis(plt, axis)
|
||||||
ax = getRightAxis(plt.o)
|
|
||||||
|
# if axis == :right
|
||||||
|
# ax = getRightAxis(plt.o)
|
||||||
ax[:set_ylabel](plt.initargs[:yrightlabel])
|
ax[:set_ylabel](plt.initargs[:yrightlabel])
|
||||||
fmap = @compat Dict(
|
fmap = @compat Dict(
|
||||||
:hist => :hist,
|
:hist => :hist,
|
||||||
@ -137,19 +153,19 @@ function getPyPlotFunction(plt::Plot, axis::Symbol, linetype::Symbol)
|
|||||||
)
|
)
|
||||||
return ax[get(fmap, linetype, :plot)]
|
return ax[get(fmap, linetype, :plot)]
|
||||||
# return ax[linetype == :hist ? :hist : (linetype in (:sticks,:bar) ? :bar : (linetype in (:heatmap,:hexbin) ? :hexbin : :plot))]
|
# return ax[linetype == :hist ? :hist : (linetype in (:sticks,:bar) ? :bar : (linetype in (:heatmap,:hexbin) ? :hexbin : :plot))]
|
||||||
end
|
# end
|
||||||
|
|
||||||
# get the function
|
# # get the function
|
||||||
fmap = @compat Dict(
|
# fmap = @compat Dict(
|
||||||
:hist => PyPlot.plt[:hist],
|
# :hist => PyPlot.plt[:hist],
|
||||||
:sticks => PyPlot.bar,
|
# :sticks => PyPlot.bar,
|
||||||
:bar => PyPlot.bar,
|
# :bar => PyPlot.bar,
|
||||||
:heatmap => PyPlot.hexbin,
|
# :heatmap => PyPlot.hexbin,
|
||||||
:hexbin => PyPlot.hexbin,
|
# :hexbin => PyPlot.hexbin,
|
||||||
:scatter => PyPlot.scatter
|
# :scatter => PyPlot.scatter
|
||||||
)
|
# )
|
||||||
return get(fmap, linetype, PyPlot.plot)
|
# return get(fmap, linetype, PyPlot.plot)
|
||||||
# return linetype == :hist ? PyPlot.plt[:hist] : (linetype in (:sticks,:bar) ? PyPlot.bar : (linetype in (:heatmap,:hexbin) ? PyPlot.hexbin : PyPlot.plot))
|
# # return linetype == :hist ? PyPlot.plt[:hist] : (linetype in (:sticks,:bar) ? PyPlot.bar : (linetype in (:heatmap,:hexbin) ? PyPlot.hexbin : PyPlot.plot))
|
||||||
end
|
end
|
||||||
|
|
||||||
function updateAxisColors(ax, fgcolor)
|
function updateAxisColors(ax, fgcolor)
|
||||||
@ -167,11 +183,11 @@ end
|
|||||||
|
|
||||||
nop() = nothing
|
nop() = nothing
|
||||||
|
|
||||||
makePyPlotCurrent(plt::Plot) = PyPlot.figure(plt.o.o[:number])
|
# makePyPlotCurrent(plt::Plot) = PyPlot.figure(plt.o.o[:number])
|
||||||
|
|
||||||
|
|
||||||
function preparePlotUpdate(plt::Plot{PyPlotPackage})
|
function preparePlotUpdate(plt::Plot{PyPlotPackage})
|
||||||
makePyPlotCurrent(plt)
|
# makePyPlotCurrent(plt)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -202,7 +218,13 @@ function plot(pkg::PyPlotPackage; kw...)
|
|||||||
d = Dict(kw)
|
d = Dict(kw)
|
||||||
w,h = map(px2inch, d[:size])
|
w,h = map(px2inch, d[:size])
|
||||||
bgcolor = getPyPlotColor(d[:background_color])
|
bgcolor = getPyPlotColor(d[:background_color])
|
||||||
fig = PyPlot.figure(; figsize = (w,h), facecolor = bgcolor, dpi = 96)
|
|
||||||
|
# standalone plots will create a figure, but not if part of a subplot (do it later)
|
||||||
|
if haskey(d, :subplot)
|
||||||
|
fig = nothing
|
||||||
|
else
|
||||||
|
fig = PyPlotFigWrapper(PyPlot.figure(; figsize = (w,h), facecolor = bgcolor, dpi = 96))
|
||||||
|
end
|
||||||
|
|
||||||
# num = fig.o[:number]
|
# num = fig.o[:number]
|
||||||
plt = Plot(fig, pkg, 0, d, Dict[])
|
plt = Plot(fig, pkg, 0, d, Dict[])
|
||||||
@ -213,10 +235,8 @@ end
|
|||||||
function plot!(pkg::PyPlotPackage, plt::Plot; kw...)
|
function plot!(pkg::PyPlotPackage, plt::Plot; kw...)
|
||||||
d = Dict(kw)
|
d = Dict(kw)
|
||||||
|
|
||||||
fig = plt.o
|
# fig = plt.o
|
||||||
# PyPlot.figure(num) # makes this current
|
ax = getAxis(plt, d[:axis])
|
||||||
# makePyPlotCurrent(plt)
|
|
||||||
|
|
||||||
lt = d[:linetype]
|
lt = d[:linetype]
|
||||||
if !(lt in supportedTypes(pkg))
|
if !(lt in supportedTypes(pkg))
|
||||||
error("linetype $(lt) is unsupported in PyPlot. Choose from: $(supportedTypes(pkg))")
|
error("linetype $(lt) is unsupported in PyPlot. Choose from: $(supportedTypes(pkg))")
|
||||||
@ -236,7 +256,8 @@ function plot!(pkg::PyPlotPackage, plt::Plot; kw...)
|
|||||||
linecolor = getPyPlotColor(d[:color])
|
linecolor = getPyPlotColor(d[:color])
|
||||||
linestyle = getPyPlotLineStyle(lt, d[:linestyle])
|
linestyle = getPyPlotLineStyle(lt, d[:linestyle])
|
||||||
for yi in d[:y]
|
for yi in d[:y]
|
||||||
func = (lt == :hline ? PyPlot.axhline : PyPlot.axvline)
|
# func = (lt == :hline ? PyPlot.axhline : PyPlot.axvline)
|
||||||
|
func = ax[lt == :hline ? :axhline : axvline]
|
||||||
func(yi, linewidth=d[:linewidth], color=linecolor, linestyle=linestyle)
|
func(yi, linewidth=d[:linewidth], color=linecolor, linestyle=linestyle)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -301,7 +322,7 @@ function plot!(pkg::PyPlotPackage, plt::Plot; kw...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# this sets the bg color inside the grid
|
# this sets the bg color inside the grid
|
||||||
ax = getLeftAxis(fig)
|
# ax = getLeftAxis(plt)
|
||||||
ax[:set_axis_bgcolor](getPyPlotColor(plt.initargs[:background_color]))
|
ax[:set_axis_bgcolor](getPyPlotColor(plt.initargs[:background_color]))
|
||||||
|
|
||||||
fillrange = d[:fillrange]
|
fillrange = d[:fillrange]
|
||||||
|
|||||||
@ -59,7 +59,7 @@ end
|
|||||||
|
|
||||||
"Do a correlation plot"
|
"Do a correlation plot"
|
||||||
function corrplot{T<:Real,S<:Real}(mat::AMat{T}, corrmat::AMat{S};
|
function corrplot{T<:Real,S<:Real}(mat::AMat{T}, corrmat::AMat{S};
|
||||||
colors = :redsblues)
|
colors = :redsblues, kw...)
|
||||||
m = size(mat,2)
|
m = size(mat,2)
|
||||||
|
|
||||||
# might be a mistake?
|
# might be a mistake?
|
||||||
@ -67,7 +67,7 @@ function corrplot{T<:Real,S<:Real}(mat::AMat{T}, corrmat::AMat{S};
|
|||||||
@assert size(corrmat) == (m,m)
|
@assert size(corrmat) == (m,m)
|
||||||
|
|
||||||
# create a subplot grid, and a gradient from -1 to 1
|
# create a subplot grid, and a gradient from -1 to 1
|
||||||
p = subplot(zeros(1,m^2), n=m^2, link=true)
|
p = subplot(zeros(1,m^2); n=m^2, link=true, kw...)
|
||||||
cgrad = ColorGradient(colors, [-1,1])
|
cgrad = ColorGradient(colors, [-1,1])
|
||||||
|
|
||||||
# make all the plots
|
# make all the plots
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user