refactored gr markers fixing bugs and enabling features; clear subplot/axis args from d in _plot

This commit is contained in:
Thomas Breloff 2016-06-20 19:51:03 -04:00
parent 9f168071ff
commit e76c3fff69
3 changed files with 67 additions and 83 deletions

View File

@ -120,33 +120,6 @@ gr_set_textcolor(c, a=nothing) = GR.settextcolorind(gr_getcolorind(c, a))
# -------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------
function gr_setmarkershape(d)
if d[:markershape] != :none
shape = d[:markershape]
if isa(shape, Shape)
d[:vertices] = vertices(shape)
else
GR.setmarkertype(gr_markertype[shape])
d[:vertices] = :none
end
end
end
function gr_polymarker(d, x, y)
if d[:vertices] != :none
vertices= d[:vertices]
dx = Float64[el[1] for el in vertices] * 0.03
dy = Float64[el[2] for el in vertices] * 0.03
GR.selntran(0)
for i = 1:length(x)
xn, yn = GR.wctondc(x[i], y[i])
GR.fillarea(xn + dx, yn + dy)
end
GR.selntran(1)
else
GR.polymarker(x, y)
end
end
# draw line segments, splitting x/y into contiguous/finite segments # draw line segments, splitting x/y into contiguous/finite segments
# note: this can be used for shapes by passing func `GR.fillarea` # note: this can be used for shapes by passing func `GR.fillarea`
@ -259,65 +232,64 @@ function normalize_zvals(zv::AVec)
end end
end end
# ---------------------------------------------------------
function gr_draw_markers(d::KW, x, y) # draw ONE Shape
if d[:markershape] in (:circle, :rect, :diamond, :utriangle, :dtriangle, function gr_draw_marker(xi, yi, msize, shape::Shape)
:pentagon, :hexagon, :heptagon, :octagon, sx, sy = shape_coords(shape)
:star4, :star5, :star6, :star7, :star8) GR.selntran(0)
# for filled markers, draw the marker border first and xi, yi = GR.wctondc(xi, yi)
# then continue drawing with reduced marker size GR.fillarea(xi + sx * 0.0015msize,
msize = 0.5 * d[:markersize] yi + sy * 0.0015msize)
GR.setmarkersize(msize) GR.selntran(1)
gr_set_markercolor(d[:markerstrokecolor], d[:markerstrokealpha]) end
gr_polymarker(d, x, y)
GR.setmarkersize(msize * 0.75) # draw ONE symbol marker
gr_set_markercolor(d[:markercolor], d[:markeralpha]) function gr_draw_marker(xi, yi, msize::Number, shape::Symbol)
end GR.setmarkertype(gr_markertype[shape])
gr_polymarker(d, x, y) GR.setmarkersize(0.3msize)
GR.polymarker([xi], [yi])
end end
function gr_draw_markers(d::KW, x, y, msize, mz, c, a) # draw the markers, one at a time
if length(x) > 0 function gr_draw_markers(d::KW, x, y, msize, mz)
mz == nothing && gr_set_markercolor(c, a) shape = d[:markershape]
if shape != :none
for i=1:length(x)
msize = cycle(msize, i)
cfunc = isa(shape, Shape) ? gr_set_fillcolor : gr_set_markercolor
cfuncind = isa(shape, Shape) ? GR.setfillcolorind : GR.setmarkercolorind
if typeof(msize) <: Number && mz == nothing # draw a filled in shape, slightly bigger, to estimate a stroke
# draw the markers all the same cfunc(d[:markerstrokecolor], d[:markerstrokealpha])
GR.setmarkersize(msize) gr_draw_marker(x[i], y[i], msize*1.2, shape, )
gr_draw_markers(d, x, y)
else # draw the shape
# draw each marker differently if mz == nothing
for i = 1:length(x) cfunc(d[:markercolor], d[:markeralpha])
if mz != nothing else
ci = round(Int, 1000 + mz[i] * 255) # pick a color from the pre-loaded gradient
GR.setmarkercolorind(ci) ci = round(Int, 1000 + cycle(mz, i) * 255)
end cfuncind(ci)
GR.setmarkersize(isa(msize, Number) ? msize : msize[mod1(i, length(msize))])
gr_polymarker(d, [x[i]], [y[i]])
end end
gr_draw_marker(x[i], y[i], msize, shape)
end end
end end
end end
function gr_draw_markers(series::Series, x, y) function gr_draw_markers(series::Series, x, y)
isempty(x) && return
d = series.d d = series.d
msize = 0.5 * d[:markersize]
mz = normalize_zvals(d[:marker_z]) mz = normalize_zvals(d[:marker_z])
# draw the marker
gr_setmarkershape(d)
GR.setfillintstyle(GR.INTSTYLE_SOLID) GR.setfillintstyle(GR.INTSTYLE_SOLID)
gr_draw_markers(d, x, y, msize, mz, d[:markercolor], d[:markeralpha]) gr_draw_markers(d, x, y, d[:markersize], mz)
# # draw the stroke
# GR.setfillintstyle(GR.INTSTYLE_HOLLOW)
# gr_draw_markers(d, x, y, msize, mz, d[:markerstrokecolor], d[:markerstrokealpha])
if mz != nothing if mz != nothing
gr_colorbar(d[:subplot]) gr_colorbar(d[:subplot])
end end
end end
# ---------------------------------------------------------
function gr_set_line(w, style, c, a) function gr_set_line(w, style, c, a)
GR.setlinetype(gr_linetype[style]) GR.setlinetype(gr_linetype[style])
@ -861,15 +833,24 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
GR.setlinetype(gr_linetype[d[:linestyle]]) GR.setlinetype(gr_linetype[d[:linestyle]])
GR.polyline([xpos - 0.07, xpos - 0.01], [ypos, ypos]) GR.polyline([xpos - 0.07, xpos - 0.01], [ypos, ypos])
end end
if st == :scatter || d[:markershape] != :none
gr_set_markercolor(d[:markercolor], d[:markeralpha]) gr_draw_markers(d, xpos-[0.06,0.02], [ypos,ypos], 10, nothing)
gr_setmarkershape(d) # shape = d[:markershape]
if st == :path # if shape != :none #st == :scatter || d[:markershape] != :none
gr_polymarker(d, [xpos - 0.06, xpos - 0.02], [ypos, ypos]) # msize = 10
else # for xoff in [0.06,0.02]
gr_polymarker(d, [xpos - 0.06, xpos - 0.04, xpos - 0.02], [ypos, ypos, ypos]) # gr_set_markercolor(d[:markerstrokecolor], d[:markerstrokealpha])
end # gr_draw_marker(xpos-xoff, ypos, msize*1.1, shape)
end # gr_set_markercolor(d[:markercolor], d[:markeralpha])
# gr_draw_marker(xpos-xoff, ypos, msize, shape)
# end
# # gr_setmarkershape(d)
# # if st == :path
# # gr_polymarker(d, [xpos - 0.06, xpos - 0.02], [ypos, ypos])
# # else
# # gr_polymarker(d, [xpos - 0.06, xpos - 0.04, xpos - 0.02], [ypos, ypos, ypos])
# # end
# end
if typeof(d[:label]) <: Array if typeof(d[:label]) <: Array
i += 1 i += 1
lab = d[:label][i] lab = d[:label][i]

View File

@ -62,6 +62,7 @@ function _initialize_backend(::PyPlotBackend)
const pyticker = PyPlot.pywrap(PyPlot.pyimport("matplotlib.ticker")) const pyticker = PyPlot.pywrap(PyPlot.pyimport("matplotlib.ticker"))
const pycmap = PyPlot.pywrap(PyPlot.pyimport("matplotlib.cm")) const pycmap = PyPlot.pywrap(PyPlot.pyimport("matplotlib.cm"))
const pynp = PyPlot.pywrap(PyPlot.pyimport("numpy")) const pynp = PyPlot.pywrap(PyPlot.pyimport("numpy"))
pynp.seterr(invalid="ignore")
const pytransforms = PyPlot.pywrap(PyPlot.pyimport("matplotlib.transforms")) const pytransforms = PyPlot.pywrap(PyPlot.pyimport("matplotlib.transforms"))
const pycollections = PyPlot.pywrap(PyPlot.pyimport("matplotlib.collections")) const pycollections = PyPlot.pywrap(PyPlot.pyimport("matplotlib.collections"))
const pyart3d = PyPlot.pywrap(PyPlot.pyimport("mpl_toolkits.mplot3d.art3d")) const pyart3d = PyPlot.pywrap(PyPlot.pyimport("mpl_toolkits.mplot3d.art3d"))

View File

@ -281,12 +281,14 @@ function _plot!(plt::Plot, d::KW, args...)
end end
# remove subplot and axis args from d... they will be passed through in the kw_list # remove subplot and axis args from d... they will be passed through in the kw_list
for (k,v) in d if !isempty(args)
for defdict in (_subplot_defaults, for (k,v) in d
_axis_defaults, for defdict in (_subplot_defaults,
_axis_defaults_byletter) _axis_defaults,
if haskey(defdict, k) _axis_defaults_byletter)
delete!(d, k) if haskey(defdict, k)
delete!(d, k)
end
end end
end end
end end