pyplot line segments fix; bar fixes

This commit is contained in:
Thomas Breloff 2016-07-08 13:09:36 -04:00
parent ec06a01b6c
commit 71b48427c5
2 changed files with 19 additions and 10 deletions

View File

@ -436,7 +436,8 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
else
# multicolored line segments
n = length(x) - 1
segments = Array(Any,n)
# segments = Array(Any,n)
segments = []
kw = KW(
:label => series[:label],
:zorder => plt.n,
@ -445,17 +446,23 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
:linestyle => py_linestyle(st, series[:linestyle])
)
handle = if is3d(st)
for i=1:n
segments[i] = [(cycle(x,i), cycle(y,i), cycle(z,i)), (cycle(x,i+1), cycle(y,i+1), cycle(z,i+1))]
for rng in iter_segments(x, y, z)
push!(segments, [(cycle(x,i),cycle(y,i),cycle(z,i)) for i in rng])
end
# for i=1:n
# segments[i] = [(cycle(x,i), cycle(y,i), cycle(z,i)), (cycle(x,i+1), cycle(y,i+1), cycle(z,i+1))]
# end
lc = pyart3d.Line3DCollection(segments; kw...)
lc[:set_array](series[:line_z])
ax[:add_collection3d](lc, zs=z) #, zdir='y')
lc
else
for i=1:n
segments[i] = [(cycle(x,i), cycle(y,i)), (cycle(x,i+1), cycle(y,i+1))]
for rng in iter_segments(x, y)
push!(segments, [(cycle(x,i),cycle(y,i)) for i in rng])
end
# for i=1:n
# segments[i] = [(cycle(x,i), cycle(y,i)), (cycle(x,i+1), cycle(y,i+1))]
# end
lc = pycollections.LineCollection(segments; kw...)
lc[:set_array](series[:line_z])
ax[:add_collection](lc)

View File

@ -394,18 +394,20 @@ end
# create a bar plot as a filled step function
@recipe function f(::Type{Val{:bar}}, x, y, z)
nx, ny = length(x), length(y)
axis = d[:subplot][isvertical(d) ? :xaxis : :yaxis]
cv = [discrete_value!(axis, xi)[1] for xi=x]
x = if nx == ny
x
cv
elseif nx == ny + 1
diff(x) + x[1:end-1]
0.5diff(cv) + cv[1:end-1]
else
error("bar recipe: x must be same length as y (centers), or one more than y (edges).\n\t\tlength(x)=$(length(x)), length(y)=$(length(y))")
end
axis = d[:subplot][isvertical(d) ? :xaxis : :yaxis]
# compute half-width of bars
bw = d[:bar_width]
hw = if bw == nothing
0.5mean(diff([discrete_value!(axis, xi)[1] for xi=x]))
0.5mean(diff(x))
else
Float64[0.5cycle(bw,i) for i=1:length(x)]
end
@ -419,7 +421,7 @@ end
# create the bar shapes by adding x/y segments
xseg, yseg = Segments(), Segments()
for i=1:ny
center = discrete_value!(axis, x[i])[1]
center = x[i]
hwi = cycle(hw,i)
yi = y[i]
fi = cycle(fillto,i)