pyplot hline/vline

This commit is contained in:
Thomas Breloff 2015-09-29 12:20:58 -04:00
parent 54f09c58cb
commit 518ccf5a74
2 changed files with 33 additions and 12 deletions

File diff suppressed because one or more lines are too long

View File

@ -51,7 +51,7 @@ supportedArgs(::PyPlotPackage) = [
:yticks, :yticks,
] ]
supportedAxes(::PyPlotPackage) = _allAxes supportedAxes(::PyPlotPackage) = _allAxes
supportedTypes(::PyPlotPackage) = [:none, :line, :path, :step, :stepinverted, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar] supportedTypes(::PyPlotPackage) = [:none, :line, :path, :step, :stepinverted, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline]
supportedStyles(::PyPlotPackage) = [:auto, :solid, :dash, :dot, :dashdot] supportedStyles(::PyPlotPackage) = [:auto, :solid, :dash, :dot, :dashdot]
supportedMarkers(::PyPlotPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :hexagon] supportedMarkers(::PyPlotPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :hexagon]
subplotSupported(::PyPlotPackage) = false subplotSupported(::PyPlotPackage) = false
@ -190,17 +190,29 @@ function plot!(pkg::PyPlotPackage, plt::Plot; kw...)
# PyPlot.figure(num) # makes this current # PyPlot.figure(num) # makes this current
# makePyPlotCurrent(plt) # makePyPlotCurrent(plt)
if !(d[:linetype] in supportedTypes(pkg)) lt = d[:linetype]
error("linetype $(d[:linetype]) is unsupported in PyPlot. Choose from: $(supportedTypes(pkg))") if !(lt in supportedTypes(pkg))
error("linetype $(lt) is unsupported in PyPlot. Choose from: $(supportedTypes(pkg))")
end end
if d[:linetype] == :sticks if lt == :sticks
d,_ = sticksHack(;d...) d,_ = sticksHack(;d...)
elseif d[:linetype] == :scatter
elseif lt == :scatter
d[:linetype] = :none d[:linetype] = :none
if d[:marker] == :none if d[:marker] == :none
d[:marker] = :ellipse d[:marker] = :ellipse
end end
elseif lt in (:hline,:vline)
linewidth = d[:width]
linecolor = getPyPlotColor(d[:color])
linestyle = getPyPlotLineStyle(lt, d[:linestyle])
for yi in d[:y]
func = (lt == :hline ? PyPlot.axhline : PyPlot.axvline)
func(yi, linewidth=d[:width], color=linecolor, linestyle=linestyle)
end
end end
lt = d[:linetype] lt = d[:linetype]
@ -340,7 +352,7 @@ end
function addPyPlotLegend(plt::Plot) function addPyPlotLegend(plt::Plot)
if plt.initargs[:legend] if plt.initargs[: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,:hexbin,:heatmap)), plt.seriesargs) args = filter(x -> !(x[:linetype] in (:hist,:hexbin,:heatmap,:hline,:vline)), plt.seriesargs)
if length(args) > 0 if length(args) > 0
PyPlot.legend([d[:serieshandle] for d in args], [d[:label] for d in args], loc="best") PyPlot.legend([d[:serieshandle] for d in args], [d[:label] for d in args], loc="best")
end end