implement vector arguments for GR and PyPlot
This commit is contained in:
parent
fc7b6dd0c6
commit
f89b1ba303
16
src/args.jl
16
src/args.jl
@ -1450,18 +1450,18 @@ end
|
|||||||
|
|
||||||
|
|
||||||
# converts a symbol or string into a colorant (Colors.RGB), and assigns a color automatically
|
# converts a symbol or string into a colorant (Colors.RGB), and assigns a color automatically
|
||||||
function getSeriesRGBColor(c, α, sp::Subplot, n::Int)
|
function getSeriesRGBColor(c, sp::Subplot, n::Int)
|
||||||
if c == :auto
|
if c == :auto
|
||||||
c = autopick(sp[:color_palette], n)
|
c = autopick(sp[:color_palette], n)
|
||||||
elseif isa(c, Int)
|
elseif isa(c, Int)
|
||||||
c = autopick(sp[:color_palette], c)
|
c = autopick(sp[:color_palette], c)
|
||||||
end
|
end
|
||||||
plot_color(c, α)
|
plot_color(c)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ensure_gradient!(d::KW, csym::Symbol, asym::Symbol)
|
function ensure_gradient!(d::KW, csym::Symbol, asym::Symbol)
|
||||||
if !isa(d[csym], ColorGradient)
|
if !isa(d[csym], ColorGradient)
|
||||||
d[csym] = cgrad(alpha = d[asym])
|
d[csym] = typeof(d[asym]) <: AbstractVector ? cgrad() : cgrad(alpha = d[asym])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1508,21 +1508,21 @@ function _add_defaults!(d::KW, plt::Plot, sp::Subplot, commandIndex::Int)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# update series color
|
# update series color
|
||||||
d[:seriescolor] = getSeriesRGBColor(d[:seriescolor], d[:seriesalpha], sp, plotIndex)
|
d[:seriescolor] = getSeriesRGBColor.(d[:seriescolor], sp, plotIndex)
|
||||||
|
|
||||||
# update other colors
|
# update other colors
|
||||||
for s in (:line, :marker, :fill)
|
for s in (:line, :marker, :fill)
|
||||||
csym, asym = Symbol(s,:color), Symbol(s,:alpha)
|
csym, asym = Symbol(s,:color), Symbol(s,:alpha)
|
||||||
d[csym] = if d[csym] == :auto
|
d[csym] = if d[csym] == :auto
|
||||||
plot_color(if has_black_border_for_default(d[:seriestype]) && s == :line
|
plot_color.(if has_black_border_for_default(d[:seriestype]) && s == :line
|
||||||
sp[:foreground_color_subplot]
|
sp[:foreground_color_subplot]
|
||||||
else
|
else
|
||||||
d[:seriescolor]
|
d[:seriescolor]
|
||||||
end, d[asym])
|
end)
|
||||||
elseif d[csym] == :match
|
elseif d[csym] == :match
|
||||||
plot_color(d[:seriescolor], d[asym])
|
plot_color.(d[:seriescolor])
|
||||||
else
|
else
|
||||||
getSeriesRGBColor(d[csym], d[asym], sp, plotIndex)
|
getSeriesRGBColor.(d[csym], sp, plotIndex)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -135,7 +135,7 @@ const gr_font_family = Dict(
|
|||||||
# --------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------------
|
||||||
|
|
||||||
function gr_getcolorind(c)
|
function gr_getcolorind(c)
|
||||||
GR.settransparency(float(alpha(c)))
|
gr_set_transparency(float(alpha(c)))
|
||||||
convert(Int, GR.inqcolorfromrgb(red(c), green(c), blue(c)))
|
convert(Int, GR.inqcolorfromrgb(red(c), green(c), blue(c)))
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -143,6 +143,7 @@ gr_set_linecolor(c) = GR.setlinecolorind(gr_getcolorind(_cycle(c,1)))
|
|||||||
gr_set_fillcolor(c) = GR.setfillcolorind(gr_getcolorind(_cycle(c,1)))
|
gr_set_fillcolor(c) = GR.setfillcolorind(gr_getcolorind(_cycle(c,1)))
|
||||||
gr_set_markercolor(c) = GR.setmarkercolorind(gr_getcolorind(_cycle(c,1)))
|
gr_set_markercolor(c) = GR.setmarkercolorind(gr_getcolorind(_cycle(c,1)))
|
||||||
gr_set_textcolor(c) = GR.settextcolorind(gr_getcolorind(_cycle(c,1)))
|
gr_set_textcolor(c) = GR.settextcolorind(gr_getcolorind(_cycle(c,1)))
|
||||||
|
gr_set_transparency(α::Real) = GR.settransparency(clamp(α, 0, 1))
|
||||||
|
|
||||||
# --------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -230,7 +231,7 @@ function gr_polaraxes(rmin::Real, rmax::Real, sp::Subplot)
|
|||||||
#draw angular grid
|
#draw angular grid
|
||||||
if xaxis[:grid]
|
if xaxis[:grid]
|
||||||
gr_set_line(xaxis[:gridlinewidth], xaxis[:gridstyle], xaxis[:foreground_color_grid])
|
gr_set_line(xaxis[:gridlinewidth], xaxis[:gridstyle], xaxis[:foreground_color_grid])
|
||||||
GR.settransparency(xaxis[:gridalpha])
|
gr_set_transparency(xaxis[:gridalpha])
|
||||||
for i in 1:length(α)
|
for i in 1:length(α)
|
||||||
GR.polyline([sinf[i], 0], [cosf[i], 0])
|
GR.polyline([sinf[i], 0], [cosf[i], 0])
|
||||||
end
|
end
|
||||||
@ -239,7 +240,7 @@ function gr_polaraxes(rmin::Real, rmax::Real, sp::Subplot)
|
|||||||
#draw radial grid
|
#draw radial grid
|
||||||
if yaxis[:grid]
|
if yaxis[:grid]
|
||||||
gr_set_line(yaxis[:gridlinewidth], yaxis[:gridstyle], yaxis[:foreground_color_grid])
|
gr_set_line(yaxis[:gridlinewidth], yaxis[:gridstyle], yaxis[:foreground_color_grid])
|
||||||
GR.settransparency(yaxis[:gridalpha])
|
gr_set_transparency(yaxis[:gridalpha])
|
||||||
for i in 1:length(rtick_values)
|
for i in 1:length(rtick_values)
|
||||||
r = (rtick_values[i] - rmin) / (rmax - rmin)
|
r = (rtick_values[i] - rmin) / (rmax - rmin)
|
||||||
if r <= 1.0 && r >= 0.0
|
if r <= 1.0 && r >= 0.0
|
||||||
@ -250,7 +251,7 @@ function gr_polaraxes(rmin::Real, rmax::Real, sp::Subplot)
|
|||||||
end
|
end
|
||||||
|
|
||||||
#prepare to draw ticks
|
#prepare to draw ticks
|
||||||
GR.settransparency(1)
|
gr_set_transparency(1)
|
||||||
GR.setlinecolorind(90)
|
GR.setlinecolorind(90)
|
||||||
GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_HALF)
|
GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_HALF)
|
||||||
|
|
||||||
@ -319,9 +320,6 @@ function normalize_zvals(zv::AVec, clims::NTuple{2, <:Real})
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
gr_alpha(α::Void) = 1
|
|
||||||
gr_alpha(α::Real) = α
|
|
||||||
|
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
# draw ONE Shape
|
# draw ONE Shape
|
||||||
@ -369,7 +367,7 @@ function gr_draw_markers(series::Series, x, y, msize, mz)
|
|||||||
# pick a color from the pre-loaded gradient
|
# pick a color from the pre-loaded gradient
|
||||||
ci = round(Int, 1000 + _cycle(mz, i) * 255)
|
ci = round(Int, 1000 + _cycle(mz, i) * 255)
|
||||||
cfuncind(ci)
|
cfuncind(ci)
|
||||||
GR.settransparency(_gr_gradient_alpha[ci-999])
|
gr_set_transparency(_gr_gradient_alpha[ci-999])
|
||||||
end
|
end
|
||||||
# don't draw filled area if marker shape is 1D
|
# don't draw filled area if marker shape is 1D
|
||||||
if !(shape in (:hline, :vline, :+, :x))
|
if !(shape in (:hline, :vline, :+, :x))
|
||||||
@ -794,21 +792,21 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
|
|
||||||
if xaxis[:grid]
|
if xaxis[:grid]
|
||||||
gr_set_line(xaxis[:gridlinewidth], xaxis[:gridstyle], xaxis[:foreground_color_grid])
|
gr_set_line(xaxis[:gridlinewidth], xaxis[:gridstyle], xaxis[:foreground_color_grid])
|
||||||
GR.settransparency(xaxis[:gridalpha])
|
gr_set_transparency(xaxis[:gridalpha])
|
||||||
GR.grid3d(xtick, 0, 0, xmin, ymax, zmin, 2, 0, 0)
|
GR.grid3d(xtick, 0, 0, xmin, ymax, zmin, 2, 0, 0)
|
||||||
end
|
end
|
||||||
if yaxis[:grid]
|
if yaxis[:grid]
|
||||||
gr_set_line(yaxis[:gridlinewidth], yaxis[:gridstyle], yaxis[:foreground_color_grid])
|
gr_set_line(yaxis[:gridlinewidth], yaxis[:gridstyle], yaxis[:foreground_color_grid])
|
||||||
GR.settransparency(yaxis[:gridalpha])
|
gr_set_transparency(yaxis[:gridalpha])
|
||||||
GR.grid3d(0, ytick, 0, xmin, ymax, zmin, 0, 2, 0)
|
GR.grid3d(0, ytick, 0, xmin, ymax, zmin, 0, 2, 0)
|
||||||
end
|
end
|
||||||
if zaxis[:grid]
|
if zaxis[:grid]
|
||||||
gr_set_line(zaxis[:gridlinewidth], zaxis[:gridstyle], zaxis[:foreground_color_grid])
|
gr_set_line(zaxis[:gridlinewidth], zaxis[:gridstyle], zaxis[:foreground_color_grid])
|
||||||
GR.settransparency(zaxis[:gridalpha])
|
gr_set_transparency(zaxis[:gridalpha])
|
||||||
GR.grid3d(0, 0, ztick, xmin, ymax, zmin, 0, 0, 2)
|
GR.grid3d(0, 0, ztick, xmin, ymax, zmin, 0, 0, 2)
|
||||||
end
|
end
|
||||||
gr_set_line(1, :solid, xaxis[:foreground_color_axis])
|
gr_set_line(1, :solid, xaxis[:foreground_color_axis])
|
||||||
GR.settransparency(1)
|
gr_set_transparency(1)
|
||||||
GR.axes3d(xtick, 0, ztick, xmin, ymin, zmin, 2, 0, 2, -ticksize)
|
GR.axes3d(xtick, 0, ztick, xmin, ymin, zmin, 2, 0, 2, -ticksize)
|
||||||
GR.axes3d(0, ytick, 0, xmax, ymin, zmin, 0, 2, 0, ticksize)
|
GR.axes3d(0, ytick, 0, xmax, ymin, zmin, 0, 2, 0, ticksize)
|
||||||
|
|
||||||
@ -831,15 +829,15 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
# gr_set_linecolor(sp[:foreground_color_grid])
|
# gr_set_linecolor(sp[:foreground_color_grid])
|
||||||
# GR.grid(xtick, ytick, 0, 0, majorx, majory)
|
# GR.grid(xtick, ytick, 0, 0, majorx, majory)
|
||||||
gr_set_line(xaxis[:gridlinewidth], xaxis[:gridstyle], xaxis[:foreground_color_grid])
|
gr_set_line(xaxis[:gridlinewidth], xaxis[:gridstyle], xaxis[:foreground_color_grid])
|
||||||
GR.settransparency(xaxis[:gridalpha])
|
gr_set_transparency(xaxis[:gridalpha])
|
||||||
gr_polyline(coords(xgrid_segs)...)
|
gr_polyline(coords(xgrid_segs)...)
|
||||||
end
|
end
|
||||||
if yaxis[:grid]
|
if yaxis[:grid]
|
||||||
gr_set_line(yaxis[:gridlinewidth], yaxis[:gridstyle], yaxis[:foreground_color_grid])
|
gr_set_line(yaxis[:gridlinewidth], yaxis[:gridstyle], yaxis[:foreground_color_grid])
|
||||||
GR.settransparency(yaxis[:gridalpha])
|
gr_set_transparency(yaxis[:gridalpha])
|
||||||
gr_polyline(coords(ygrid_segs)...)
|
gr_polyline(coords(ygrid_segs)...)
|
||||||
end
|
end
|
||||||
GR.settransparency(1.0)
|
gr_set_transparency(1.0)
|
||||||
|
|
||||||
# axis lines
|
# axis lines
|
||||||
if xaxis[:showaxis]
|
if xaxis[:showaxis]
|
||||||
@ -858,7 +856,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
if xaxis[:showaxis]
|
if xaxis[:showaxis]
|
||||||
if sp[:framestyle] in (:zerolines, :grid)
|
if sp[:framestyle] in (:zerolines, :grid)
|
||||||
gr_set_line(1, :solid, xaxis[:foreground_color_grid])
|
gr_set_line(1, :solid, xaxis[:foreground_color_grid])
|
||||||
GR.settransparency(xaxis[:gridalpha])
|
gr_set_transparency(xaxis[:gridalpha])
|
||||||
else
|
else
|
||||||
gr_set_line(1, :solid, xaxis[:foreground_color_axis])
|
gr_set_line(1, :solid, xaxis[:foreground_color_axis])
|
||||||
end
|
end
|
||||||
@ -868,7 +866,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
if yaxis[:showaxis]
|
if yaxis[:showaxis]
|
||||||
if sp[:framestyle] in (:zerolines, :grid)
|
if sp[:framestyle] in (:zerolines, :grid)
|
||||||
gr_set_line(1, :solid, yaxis[:foreground_color_grid])
|
gr_set_line(1, :solid, yaxis[:foreground_color_grid])
|
||||||
GR.settransparency(yaxis[:gridalpha])
|
gr_set_transparency(yaxis[:gridalpha])
|
||||||
else
|
else
|
||||||
gr_set_line(1, :solid, yaxis[:foreground_color_axis])
|
gr_set_line(1, :solid, yaxis[:foreground_color_axis])
|
||||||
end
|
end
|
||||||
@ -920,10 +918,10 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
intensity = sp[:framestyle] == :semi ? 0.5 : 1.0
|
intensity = sp[:framestyle] == :semi ? 0.5 : 1.0
|
||||||
if sp[:framestyle] in (:box, :semi)
|
if sp[:framestyle] in (:box, :semi)
|
||||||
gr_set_line(intensity, :solid, xaxis[:foreground_color_border])
|
gr_set_line(intensity, :solid, xaxis[:foreground_color_border])
|
||||||
GR.settransparency(intensity)
|
gr_set_transparency(intensity)
|
||||||
gr_polyline(coords(xborder_segs)...)
|
gr_polyline(coords(xborder_segs)...)
|
||||||
gr_set_line(intensity, :solid, yaxis[:foreground_color_border])
|
gr_set_line(intensity, :solid, yaxis[:foreground_color_border])
|
||||||
GR.settransparency(intensity)
|
gr_set_transparency(intensity)
|
||||||
gr_polyline(coords(yborder_segs)...)
|
gr_polyline(coords(yborder_segs)...)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1030,7 +1028,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
gr_set_fillcolor(get_fillcolor(series, i))
|
gr_set_fillcolor(get_fillcolor(series, i))
|
||||||
fx = _cycle(x, vcat(rng, reverse(rng)))
|
fx = _cycle(x, vcat(rng, reverse(rng)))
|
||||||
fy = vcat(_cycle(fr_from,rng), _cycle(fr_to,reverse(rng)))
|
fy = vcat(_cycle(fr_from,rng), _cycle(fr_to,reverse(rng)))
|
||||||
series[:fillalpha] != nothing && GR.settransparency(series[:fillalpha])
|
gr_set_transparency(get_fillalpha(series, i))
|
||||||
GR.fillarea(fx, fy)
|
GR.fillarea(fx, fy)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1038,7 +1036,8 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
# draw the line(s)
|
# draw the line(s)
|
||||||
if st in (:path, :straightline)
|
if st in (:path, :straightline)
|
||||||
for (i, rng) in enumerate(segments)
|
for (i, rng) in enumerate(segments)
|
||||||
gr_set_line(series[:linewidth], series[:linestyle], get_linecolor(series, i)) #, series[:linealpha])
|
gr_set_line(get_linewidth(series, i), get_linestyle(series, i), get_linecolor(series, i)) #, series[:linealpha])
|
||||||
|
gr_set_transparency(get_linealpha(series, i))
|
||||||
arrowside = isa(series[:arrow], Arrow) ? series[:arrow].side : :none
|
arrowside = isa(series[:arrow], Arrow) ? series[:arrow].side : :none
|
||||||
gr_polyline(x[rng], y[rng]; arrowside = arrowside)
|
gr_polyline(x[rng], y[rng]; arrowside = arrowside)
|
||||||
end
|
end
|
||||||
@ -1064,8 +1063,8 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
if series[:fillrange] != nothing
|
if series[:fillrange] != nothing
|
||||||
GR.surface(x, y, z, GR.OPTION_CELL_ARRAY)
|
GR.surface(x, y, z, GR.OPTION_CELL_ARRAY)
|
||||||
else
|
else
|
||||||
GR.setlinetype(gr_linetype[series[:linestyle]])
|
GR.setlinetype(gr_linetype[get_linestyle(series)])
|
||||||
GR.setlinewidth(max(0, series[:linewidth] / (sum(gr_plot_size) * 0.001)))
|
GR.setlinewidth(max(0, get_linewidth(series) / (sum(gr_plot_size) * 0.001)))
|
||||||
if plot_color(series[:linecolor]) == [plot_color(:black)]
|
if plot_color(series[:linecolor]) == [plot_color(:black)]
|
||||||
GR.contour(x, y, h, z, 0 + (series[:contour_labels] == true ? 1 : 0))
|
GR.contour(x, y, h, z, 0 + (series[:contour_labels] == true ? 1 : 0))
|
||||||
else
|
else
|
||||||
@ -1117,7 +1116,8 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
lz = series[:line_z]
|
lz = series[:line_z]
|
||||||
segments = iter_segments(series)
|
segments = iter_segments(series)
|
||||||
for (i, rng) in enumerate(segments)
|
for (i, rng) in enumerate(segments)
|
||||||
gr_set_line(series[:linewidth], series[:linestyle], get_linecolor(series, i)) #, series[:linealpha])
|
gr_set_line(get_linewidth(series, i), get_linestyle(series, i), get_linecolor(series, i)) #, series[:linealpha])
|
||||||
|
gr_set_transparency(get_linealpha(series, i))
|
||||||
GR.polyline3d(x[rng], y[rng], z[rng])
|
GR.polyline3d(x[rng], y[rng], z[rng])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1189,10 +1189,12 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
|
|
||||||
# draw the interior
|
# draw the interior
|
||||||
gr_set_fill(get_fillcolor(series, i))
|
gr_set_fill(get_fillcolor(series, i))
|
||||||
|
gr_set_transparency(get_fillalpha(series, i))
|
||||||
GR.fillarea(xseg, yseg)
|
GR.fillarea(xseg, yseg)
|
||||||
|
|
||||||
# draw the shapes
|
# draw the shapes
|
||||||
gr_set_line(series[:linewidth], :solid, get_linecolor(series, i))
|
gr_set_line(get_linewidth(series, i), get_linestyle(series, i), get_linecolor(series, i))
|
||||||
|
gr_set_transparency(get_linealpha(series, i))
|
||||||
GR.polyline(xseg, yseg)
|
GR.polyline(xseg, yseg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1224,7 +1226,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
# draw the colorbar
|
# draw the colorbar
|
||||||
if cmap && st != :contour # special colorbar with steps is drawn for contours
|
if cmap && st != :contour # special colorbar with steps is drawn for contours
|
||||||
gr_set_line(1, :solid, yaxis[:foreground_color_axis])
|
gr_set_line(1, :solid, yaxis[:foreground_color_axis])
|
||||||
GR.settransparency(1)
|
gr_set_transparency(1)
|
||||||
gr_colorbar(sp, clims)
|
gr_colorbar(sp, clims)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1271,14 +1273,14 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
if sp[:legendtitle] != nothing
|
if sp[:legendtitle] != nothing
|
||||||
GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_HALF)
|
GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_HALF)
|
||||||
gr_set_textcolor(sp[:legendfontcolor])
|
gr_set_textcolor(sp[:legendfontcolor])
|
||||||
GR.settransparency(1)
|
gr_set_transparency(1)
|
||||||
gr_text(xpos - 0.03 + 0.5*w, ypos, string(sp[:legendtitle]))
|
gr_text(xpos - 0.03 + 0.5*w, ypos, string(sp[:legendtitle]))
|
||||||
ypos -= dy
|
ypos -= dy
|
||||||
end
|
end
|
||||||
for series in series_list(sp)
|
for series in series_list(sp)
|
||||||
should_add_to_legend(series) || continue
|
should_add_to_legend(series) || continue
|
||||||
st = series[:seriestype]
|
st = series[:seriestype]
|
||||||
gr_set_line(series[:linewidth], series[:linestyle], get_linecolor(series)) #, series[:linealpha])
|
gr_set_line(get_linewidth(series), get_linestyle(series), get_linecolor(series)) #, series[:linealpha])
|
||||||
|
|
||||||
if (st == :shape || series[:fillrange] != nothing) && series[:ribbon] == nothing
|
if (st == :shape || series[:fillrange] != nothing) && series[:ribbon] == nothing
|
||||||
gr_set_fill(get_fillcolor(series)) #, series[:fillalpha])
|
gr_set_fill(get_fillcolor(series)) #, series[:fillalpha])
|
||||||
@ -1286,14 +1288,15 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
b, t = ypos-0.4dy, ypos+0.4dy
|
b, t = ypos-0.4dy, ypos+0.4dy
|
||||||
x = [l, r, r, l, l]
|
x = [l, r, r, l, l]
|
||||||
y = [b, b, t, t, b]
|
y = [b, b, t, t, b]
|
||||||
GR.settransparency(gr_alpha(series[:fillalpha]))
|
gr_set_transparency(get_fillalpha(series))
|
||||||
gr_polyline(x, y, GR.fillarea)
|
gr_polyline(x, y, GR.fillarea)
|
||||||
GR.settransparency(gr_alpha(series[:linealpha]))
|
gr_set_transparency(get_linealpha(series))
|
||||||
|
gr_set_line(get_linewidth(series), get_linestyle(series), get_linecolor(series))
|
||||||
st == :shape && gr_polyline(x, y)
|
st == :shape && gr_polyline(x, y)
|
||||||
end
|
end
|
||||||
|
|
||||||
if st in (:path, :straightline)
|
if st in (:path, :straightline)
|
||||||
GR.settransparency(gr_alpha(series[:linealpha]))
|
gr_set_transparency(get_linealpha(series))
|
||||||
if series[:fillrange] == nothing || series[:ribbon] != nothing
|
if series[:fillrange] == nothing || series[:ribbon] != nothing
|
||||||
GR.polyline([xpos - 0.07, xpos - 0.01], [ypos, ypos])
|
GR.polyline([xpos - 0.07, xpos - 0.01], [ypos, ypos])
|
||||||
else
|
else
|
||||||
|
|||||||
@ -136,6 +136,7 @@ py_color(s) = py_color(parse(Colorant, string(s)))
|
|||||||
py_color(c::Colorant) = (red(c), green(c), blue(c), alpha(c))
|
py_color(c::Colorant) = (red(c), green(c), blue(c), alpha(c))
|
||||||
py_color(cs::AVec) = map(py_color, cs)
|
py_color(cs::AVec) = map(py_color, cs)
|
||||||
py_color(grad::ColorGradient) = py_color(grad.colors)
|
py_color(grad::ColorGradient) = py_color(grad.colors)
|
||||||
|
py_color(c::Colorant, α) = py_color(plot_color(c, α))
|
||||||
|
|
||||||
function py_colormap(grad::ColorGradient)
|
function py_colormap(grad::ColorGradient)
|
||||||
pyvals = [(z, py_color(grad[z])) for z in grad.values]
|
pyvals = [(z, py_color(grad[z])) for z in grad.values]
|
||||||
@ -492,60 +493,49 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
|
|
||||||
# line plot
|
# line plot
|
||||||
if st in (:path, :path3d, :steppre, :steppost, :straightline)
|
if st in (:path, :path3d, :steppre, :steppost, :straightline)
|
||||||
if series[:linewidth] > 0
|
if maximum(series[:linewidth]) > 0
|
||||||
if series[:line_z] == nothing
|
segments = iter_segments(series)
|
||||||
handle = ax[:plot](xyargs...;
|
if length(segments) > 1 && (any(typeof(series[attr]) <: AbstractVector for attr in (:fillcolor, :fillalpha)) || series[:fill_z] != nothing)
|
||||||
label = series[:label],
|
|
||||||
zorder = series[:series_plotindex],
|
|
||||||
color = py_linecolor(series),
|
|
||||||
linewidth = py_dpi_scale(plt, series[:linewidth]),
|
|
||||||
linestyle = py_linestyle(st, series[:linestyle]),
|
|
||||||
solid_capstyle = "round",
|
|
||||||
drawstyle = py_stepstyle(st)
|
|
||||||
)[1]
|
|
||||||
push!(handles, handle)
|
|
||||||
|
|
||||||
else
|
|
||||||
# multicolored line segments
|
# multicolored line segments
|
||||||
n = length(x) - 1
|
n = length(segments)
|
||||||
# segments = Array(Any,n)
|
# segments = Array(Any,n)
|
||||||
segments = []
|
segments = []
|
||||||
kw = KW(
|
kw = KW(
|
||||||
:label => series[:label],
|
:label => series[:label],
|
||||||
:zorder => plt.n,
|
:zorder => plt.n,
|
||||||
:cmap => py_linecolormap(series),
|
:cmap => py_linecolormap(series),
|
||||||
:linewidth => py_dpi_scale(plt, series[:linewidth]),
|
:linewidths => py_dpi_scale(plt, get_linewidth.(series, 1:n)),
|
||||||
:linestyle => py_linestyle(st, series[:linestyle]),
|
:linestyles => py_linestyle(st, get_linestyle(series, 1:n)),
|
||||||
:norm => pycolors["Normalize"](; extrakw...)
|
:norm => pycolors["Normalize"](; extrakw...)
|
||||||
)
|
)
|
||||||
lz = _cycle(series[:line_z], 1:n)
|
lz = _cycle(series[:line_z], 1:n)
|
||||||
handle = if is3d(st)
|
handle = if is3d(st)
|
||||||
for rng in iter_segments(x, y, z)
|
line_segments = [[(x[j], y[j], z[j]) for j in rng] for rng in segments]
|
||||||
length(rng) < 2 && continue
|
lc = pyart3d["Line3DCollection"](line_segments; kw...)
|
||||||
for i in rng[1:end-1]
|
|
||||||
push!(segments, [(_cycle(x,i),_cycle(y,i),_cycle(z,i)),
|
|
||||||
(_cycle(x,i+1),_cycle(y,i+1),_cycle(z,i+1))])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
lc = pyart3d["Line3DCollection"](segments; kw...)
|
|
||||||
lc[:set_array](lz)
|
lc[:set_array](lz)
|
||||||
ax[:add_collection3d](lc, zs=z) #, zdir='y')
|
ax[:add_collection3d](lc, zs=z) #, zdir='y')
|
||||||
lc
|
lc
|
||||||
else
|
else
|
||||||
for rng in iter_segments(x, y)
|
line_segments = [[(x[j], y[j]) for j in rng] for rng in segments]
|
||||||
length(rng) < 2 && continue
|
lc = pycollections["LineCollection"](line_segments; kw...)
|
||||||
for i in rng[1:end-1]
|
|
||||||
push!(segments, [(_cycle(x,i),_cycle(y,i)), (_cycle(x,i+1),_cycle(y,i+1))])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
lc = pycollections["LineCollection"](segments; kw...)
|
|
||||||
lc[:set_array](lz)
|
lc[:set_array](lz)
|
||||||
ax[:add_collection](lc)
|
ax[:add_collection](lc)
|
||||||
lc
|
lc
|
||||||
end
|
end
|
||||||
push!(handles, handle)
|
push!(handles, handle)
|
||||||
|
else
|
||||||
|
for (i, rng) in enumerate(iter_segments(series))
|
||||||
|
handle = ax[:plot]((arg[rng] for arg in xyargs)...;
|
||||||
|
label = i == 1 ? series[:label] : "",
|
||||||
|
zorder = series[:series_plotindex],
|
||||||
|
color = py_color(get_linecolor(series, i), get_linealpha(series, i)),
|
||||||
|
linewidth = py_dpi_scale(plt, get_linewidth(series, i)),
|
||||||
|
linestyle = py_linestyle(st, get_linestyle(series, i)),
|
||||||
|
solid_capstyle = "round",
|
||||||
|
drawstyle = py_stepstyle(st)
|
||||||
|
)[1]
|
||||||
|
push!(handles, handle)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
a = series[:arrow]
|
a = series[:arrow]
|
||||||
@ -559,8 +549,8 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
:shrinkB => 0,
|
:shrinkB => 0,
|
||||||
:edgecolor => py_linecolor(series),
|
:edgecolor => py_linecolor(series),
|
||||||
:facecolor => py_linecolor(series),
|
:facecolor => py_linecolor(series),
|
||||||
:linewidth => py_dpi_scale(plt, series[:linewidth]),
|
:linewidth => py_dpi_scale(plt, get_linewidth(series)),
|
||||||
:linestyle => py_linestyle(st, series[:linestyle]),
|
:linestyle => py_linestyle(st, get_linestyle(series)),
|
||||||
)
|
)
|
||||||
add_arrows(x, y) do xyprev, xy
|
add_arrows(x, y) do xyprev, xy
|
||||||
ax[:annotate]("",
|
ax[:annotate]("",
|
||||||
@ -794,16 +784,17 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
|
|
||||||
if st == :shape
|
if st == :shape
|
||||||
handle = []
|
handle = []
|
||||||
for (i,rng) in enumerate(iter_segments(x, y))
|
for (i, rng) in enumerate(iter_segments(series))
|
||||||
if length(rng) > 1
|
if length(rng) > 1
|
||||||
path = pypath["Path"](hcat(x[rng], y[rng]))
|
path = pypath["Path"](hcat(x[rng], y[rng]))
|
||||||
patches = pypatches["PathPatch"](
|
patches = pypatches["PathPatch"](
|
||||||
path;
|
path;
|
||||||
label = series[:label],
|
label = series[:label],
|
||||||
zorder = series[:series_plotindex],
|
zorder = series[:series_plotindex],
|
||||||
edgecolor = py_color(_cycle(series[:linecolor], i)),
|
edgecolor = py_color(get_linecolor(series, i), get_linealpha(series, i)),
|
||||||
facecolor = py_color(_cycle(series[:fillcolor], i)),
|
facecolor = py_color(get_fillcolor(series, i), get_fillalpha(series, i)),
|
||||||
linewidth = py_dpi_scale(plt, series[:linewidth]),
|
linewidth = py_dpi_scale(plt, get_linewidth(series, i)),
|
||||||
|
linestyle = py_linestyle(st, get_linestyle(series, i)),
|
||||||
fill = true
|
fill = true
|
||||||
)
|
)
|
||||||
push!(handle, ax[:add_patch](patches))
|
push!(handle, ax[:add_patch](patches))
|
||||||
@ -835,10 +826,11 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
# handle area filling
|
# handle area filling
|
||||||
fillrange = series[:fillrange]
|
fillrange = series[:fillrange]
|
||||||
if fillrange != nothing && st != :contour
|
if fillrange != nothing && st != :contour
|
||||||
|
for (i, rng) in enumerate(iter_segments(series))
|
||||||
f, dim1, dim2 = if isvertical(series)
|
f, dim1, dim2 = if isvertical(series)
|
||||||
:fill_between, x, y
|
:fill_between, x[rng], y[rng]
|
||||||
else
|
else
|
||||||
:fill_betweenx, y, x
|
:fill_betweenx, y[rng], x[rng]
|
||||||
end
|
end
|
||||||
n = length(dim1)
|
n = length(dim1)
|
||||||
args = if typeof(fillrange) <: Union{Real, AVec}
|
args = if typeof(fillrange) <: Union{Real, AVec}
|
||||||
@ -849,11 +841,12 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
|
|
||||||
handle = ax[f](args..., trues(n), false, py_fillstepstyle(st);
|
handle = ax[f](args..., trues(n), false, py_fillstepstyle(st);
|
||||||
zorder = series[:series_plotindex],
|
zorder = series[:series_plotindex],
|
||||||
facecolor = py_fillcolor(series),
|
facecolor = py_color(get_fillcolor(series, i), get_fillalpha(series, i)),
|
||||||
linewidths = 0
|
linewidths = 0
|
||||||
)
|
)
|
||||||
push!(handles, handle)
|
push!(handles, handle)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# this is all we need to add the series_annotations text
|
# this is all we need to add the series_annotations text
|
||||||
anns = series[:series_annotations]
|
anns = series[:series_annotations]
|
||||||
@ -1020,6 +1013,13 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
|
|||||||
kw[:ticks] = locator
|
kw[:ticks] = locator
|
||||||
kw[:format] = formatter
|
kw[:format] = formatter
|
||||||
kw[:boundaries] = vcat(0, kw[:values] + 0.5)
|
kw[:boundaries] = vcat(0, kw[:values] + 0.5)
|
||||||
|
elseif any(colorbar_series[attr] != nothing for attr in (:line_z, :fill_z))
|
||||||
|
cmin, cmax = get_clims(sp)
|
||||||
|
norm = pycolors[:Normalize](vmin = cmin, vmax = cmax)
|
||||||
|
f = colorbar_series[:line_z] != nothing ? py_linecolormap : py_fillcolormap
|
||||||
|
cmap = pycmap[:ScalarMappable](norm = norm, cmap = f(colorbar_series))
|
||||||
|
cmap[:set_array]([])
|
||||||
|
handle = cmap
|
||||||
end
|
end
|
||||||
|
|
||||||
# create and store the colorbar object (handle) and the axis that it is drawn on.
|
# create and store the colorbar object (handle) and the axis that it is drawn on.
|
||||||
@ -1250,15 +1250,16 @@ function py_add_legend(plt::Plot, sp::Subplot, ax)
|
|||||||
# add a line/marker and a label
|
# add a line/marker and a label
|
||||||
push!(handles, if series[:seriestype] == :shape || series[:fillrange] != nothing
|
push!(handles, if series[:seriestype] == :shape || series[:fillrange] != nothing
|
||||||
pypatches[:Patch](
|
pypatches[:Patch](
|
||||||
edgecolor = py_color(_cycle(series[:linecolor],1)),
|
edgecolor = py_color(get_linecolor(series), get_linealpha(series)),
|
||||||
facecolor = py_color(_cycle(series[:fillcolor],1)),
|
facecolor = py_color(get_fillcolor(series), get_fillalpha(series)),
|
||||||
linewidth = py_dpi_scale(plt, clamp(series[:linewidth], 0, 5)),
|
linewidth = py_dpi_scale(plt, clamp(get_linewidth(series), 0, 5)),
|
||||||
|
linestyle = py_linestyle(series[:seriestype], get_linestyle(series))
|
||||||
)
|
)
|
||||||
elseif series[:seriestype] in (:path, :straightline)
|
elseif series[:seriestype] in (:path, :straightline)
|
||||||
PyPlot.plt[:Line2D]((0,1),(0,0),
|
PyPlot.plt[:Line2D]((0,1),(0,0),
|
||||||
color = py_color(_cycle(series[:linecolor],1)),
|
color = py_color(get_linecolor(series), get_linealpha(series)),
|
||||||
linewidth = py_dpi_scale(plt, clamp(series[:linewidth], 0, 5)),
|
linewidth = py_dpi_scale(plt, clamp(get_linewidth(series), 0, 5)),
|
||||||
linestyle = py_linestyle(:path,series[:linestyle]),
|
linestyles = py_linestyle(:path, get_linestyle(series)),
|
||||||
marker = py_marker(series[:markershape]),
|
marker = py_marker(series[:markershape]),
|
||||||
markeredgecolor = py_markerstrokecolor(series),
|
markeredgecolor = py_markerstrokecolor(series),
|
||||||
markerfacecolor = series[:marker_z] == nothing ? py_markercolor(series) : py_color(series[:markercolor][0.5])
|
markerfacecolor = series[:marker_z] == nothing ? py_markercolor(series) : py_color(series[:markercolor][0.5])
|
||||||
|
|||||||
17
src/utils.jl
17
src/utils.jl
@ -628,6 +628,18 @@ function get_linecolor(series::Series, i::Int = 1)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function get_linealpha(series::Series, i::Int = 1)
|
||||||
|
_cycle(series[:linealpha], i)
|
||||||
|
end
|
||||||
|
|
||||||
|
function get_linewidth(series::Series, i::Int = 1)
|
||||||
|
_cycle(series[:linewidth], i)
|
||||||
|
end
|
||||||
|
|
||||||
|
function get_linestyle(series::Series, i::Int = 1)
|
||||||
|
_cycle(series[:linestyle], i)
|
||||||
|
end
|
||||||
|
|
||||||
function get_fillcolor(series::Series, i::Int = 1)
|
function get_fillcolor(series::Series, i::Int = 1)
|
||||||
fc = series[:fillcolor]
|
fc = series[:fillcolor]
|
||||||
fz = series[:fill_z]
|
fz = series[:fill_z]
|
||||||
@ -645,6 +657,10 @@ function get_fillcolor(series::Series, i::Int = 1)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function get_fillalpha(series::Series, i::Int = 1)
|
||||||
|
_cycle(series[:fillalpha], i)
|
||||||
|
end
|
||||||
|
|
||||||
function has_attribute_segments(series::Series)
|
function has_attribute_segments(series::Series)
|
||||||
# we want to check if a series needs to be split into segments just because
|
# we want to check if a series needs to be split into segments just because
|
||||||
# of its attributes
|
# of its attributes
|
||||||
@ -653,6 +669,7 @@ function has_attribute_segments(series::Series)
|
|||||||
# SegmentsIterator is used
|
# SegmentsIterator is used
|
||||||
series[letter] != nothing && NaN in series[letter] && return false
|
series[letter] != nothing && NaN in series[letter] && return false
|
||||||
end
|
end
|
||||||
|
series[:seriestype] == :shape && return false
|
||||||
# ... else we check relevant attributes if they have multiple inputs
|
# ... else we check relevant attributes if they have multiple inputs
|
||||||
return any((typeof(series[attr]) <: AbstractVector && length(series[attr]) > 1) for attr in [:seriescolor, :seriesalpha, :linecolor, :linealpha, :linewidth, :fillcolor, :fillalpha]) || any(typeof(series[attr]) <: AbstractArray{<:Real} for attr in (:line_z, :fill_z))
|
return any((typeof(series[attr]) <: AbstractVector && length(series[attr]) > 1) for attr in [:seriescolor, :seriesalpha, :linecolor, :linealpha, :linewidth, :fillcolor, :fillalpha]) || any(typeof(series[attr]) <: AbstractArray{<:Real} for attr in (:line_z, :fill_z))
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user