add zerolines framestyle
This commit is contained in:
parent
3fd745a5df
commit
456b8258c3
@ -181,15 +181,13 @@ function hasgrid(arg::Symbol, letter)
|
|||||||
end
|
end
|
||||||
hasgrid(arg::AbstractString, letter) = hasgrid(Symbol(arg), letter)
|
hasgrid(arg::AbstractString, letter) = hasgrid(Symbol(arg), letter)
|
||||||
|
|
||||||
const _allFramestyles = [:box, :semi, :axes, :origin, :grid, :none]
|
const _allFramestyles = [:box, :semi, :axes, :origin, :zerolines, :grid, :none]
|
||||||
const _framestyleAliases = Dict{Symbol, Symbol}(
|
const _framestyleAliases = Dict{Symbol, Symbol}(
|
||||||
:frame => :box,
|
:frame => :box,
|
||||||
:border => :box,
|
:border => :box,
|
||||||
:on => :box,
|
:on => :box,
|
||||||
:transparent => :semi,
|
:transparent => :semi,
|
||||||
:semitransparent => :semi,
|
:semitransparent => :semi,
|
||||||
:zeroline => :origin,
|
|
||||||
:zero => :origin,
|
|
||||||
)
|
)
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
26
src/axes.jl
26
src/axes.jl
@ -508,6 +508,8 @@ function axis_drawing_info(sp::Subplot)
|
|||||||
yticks = get_ticks(yaxis)
|
yticks = get_ticks(yaxis)
|
||||||
xaxis_segs = Segments(2)
|
xaxis_segs = Segments(2)
|
||||||
yaxis_segs = Segments(2)
|
yaxis_segs = Segments(2)
|
||||||
|
xtick_segs = Segments(2)
|
||||||
|
ytick_segs = Segments(2)
|
||||||
xgrid_segs = Segments(2)
|
xgrid_segs = Segments(2)
|
||||||
ygrid_segs = Segments(2)
|
ygrid_segs = Segments(2)
|
||||||
xborder_segs = Segments(2)
|
xborder_segs = Segments(2)
|
||||||
@ -515,12 +517,13 @@ function axis_drawing_info(sp::Subplot)
|
|||||||
|
|
||||||
if !(sp[:framestyle] == :none)
|
if !(sp[:framestyle] == :none)
|
||||||
# xaxis
|
# xaxis
|
||||||
sp[:framestyle] in (:grid, :origin) || push!(xaxis_segs, (xmin,ymin), (xmax,ymin)) # bottom spine / xaxis
|
sp[:framestyle] in (:grid, :origin, :zerolines) || push!(xaxis_segs, (xmin,ymin), (xmax,ymin)) # bottom spine / xaxis
|
||||||
if sp[:framestyle] == :origin
|
if sp[:framestyle] in (:origin, :zerolines)
|
||||||
push!(xaxis_segs, (xmin, 0.0), (xmax, 0.0))
|
push!(xaxis_segs, (xmin, 0.0), (xmax, 0.0))
|
||||||
# don't show the 0 tick label for the origin framestyle
|
# don't show the 0 tick label for the origin framestyle
|
||||||
if length(yticks) > 1
|
if sp[:framestyle] == :origin && length(xticks) > 1
|
||||||
xticks[2][xticks[1] .== 0] = ""
|
showticks = xticks[1] .!= 0
|
||||||
|
xticks = (xticks[1][showticks], xticks[2][showticks])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
sp[:framestyle] in (:semi, :box) && push!(xborder_segs, (xmin,ymax), (xmax,ymax)) # top spine
|
sp[:framestyle] in (:semi, :box) && push!(xborder_segs, (xmin,ymax), (xmax,ymax)) # top spine
|
||||||
@ -537,19 +540,20 @@ function axis_drawing_info(sp::Subplot)
|
|||||||
else
|
else
|
||||||
xaxis[:mirror] ? (ymax, t2) : (ymin, t1)
|
xaxis[:mirror] ? (ymax, t2) : (ymin, t1)
|
||||||
end
|
end
|
||||||
push!(xaxis_segs, (xtick, tick_start), (xtick, tick_stop)) # bottom tick
|
push!(xtick_segs, (xtick, tick_start), (xtick, tick_stop)) # bottom tick
|
||||||
# sp[:draw_axes_border] && push!(xaxis_segs, (xtick, ymax), (xtick, t2)) # top tick
|
# sp[:draw_axes_border] && push!(xaxis_segs, (xtick, ymax), (xtick, t2)) # top tick
|
||||||
xaxis[:grid] && push!(xgrid_segs, (xtick, t1), (xtick, t2)) # vertical grid
|
xaxis[:grid] && push!(xgrid_segs, (xtick, t1), (xtick, t2)) # vertical grid
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# yaxis
|
# yaxis
|
||||||
sp[:framestyle] in (:grid, :origin) || push!(yaxis_segs, (xmin,ymin), (xmin,ymax)) # left spine / yaxis
|
sp[:framestyle] in (:grid, :origin, :zerolines) || push!(yaxis_segs, (xmin,ymin), (xmin,ymax)) # left spine / yaxis
|
||||||
if sp[:framestyle] == :origin
|
if sp[:framestyle] in (:origin, :zerolines)
|
||||||
push!(yaxis_segs, (0.0, ymin), (0.0, ymax))
|
push!(yaxis_segs, (0.0, ymin), (0.0, ymax))
|
||||||
# don't show the 0 tick label for the origin framestyle
|
# don't show the 0 tick label for the origin framestyle
|
||||||
if length(yticks) > 1
|
if sp[:framestyle] == :origin && length(yticks) > 1
|
||||||
yticks[2][yticks[1] .== 0] = ""
|
showticks = yticks[1] .!= 0
|
||||||
|
yticks = (yticks[1][showticks], yticks[2][showticks])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
sp[:framestyle] in (:semi, :box) && push!(yborder_segs, (xmax,ymin), (xmax,ymax)) # right spine
|
sp[:framestyle] in (:semi, :box) && push!(yborder_segs, (xmax,ymin), (xmax,ymax)) # right spine
|
||||||
@ -566,12 +570,12 @@ function axis_drawing_info(sp::Subplot)
|
|||||||
else
|
else
|
||||||
yaxis[:mirror] ? (xmax, t2) : (xmin, t1)
|
yaxis[:mirror] ? (xmax, t2) : (xmin, t1)
|
||||||
end
|
end
|
||||||
push!(yaxis_segs, (tick_start, ytick), (tick_stop, ytick)) # left tick
|
push!(ytick_segs, (tick_start, ytick), (tick_stop, ytick)) # left tick
|
||||||
# sp[:draw_axes_border] && push!(yaxis_segs, (xmax, ytick), (t2, ytick)) # right tick
|
# sp[:draw_axes_border] && push!(yaxis_segs, (xmax, ytick), (t2, ytick)) # right tick
|
||||||
yaxis[:grid] && push!(ygrid_segs, (t1, ytick), (t2, ytick)) # horizontal grid
|
yaxis[:grid] && push!(ygrid_segs, (t1, ytick), (t2, ytick)) # horizontal grid
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
xticks, yticks, xaxis_segs, yaxis_segs, xgrid_segs, ygrid_segs, xborder_segs, yborder_segs
|
xticks, yticks, xaxis_segs, yaxis_segs, xtick_segs, ytick_segs, xgrid_segs, ygrid_segs, xborder_segs, yborder_segs
|
||||||
end
|
end
|
||||||
|
|||||||
@ -682,7 +682,7 @@ function text_model(font, pivot)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, area)
|
function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, area)
|
||||||
xticks, yticks, xspine_segs, yspine_segs, xgrid_segs, ygrid_segs, xborder_segs, yborder_segs = Plots.axis_drawing_info(sp)
|
xticks, yticks, xspine_segs, yspine_segs, xtick_segs, ytick_segs, xgrid_segs, ygrid_segs, xborder_segs, yborder_segs = Plots.axis_drawing_info(sp)
|
||||||
xaxis = sp[:xaxis]; yaxis = sp[:yaxis]
|
xaxis = sp[:xaxis]; yaxis = sp[:yaxis]
|
||||||
|
|
||||||
xgc = Colors.color(Plots.gl_color(xaxis[:foreground_color_grid]))
|
xgc = Colors.color(Plots.gl_color(xaxis[:foreground_color_grid]))
|
||||||
@ -707,6 +707,25 @@ function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, are
|
|||||||
spine = draw_grid_lines(sp, yspine_segs, 1f0, :solid, model, RGBA(yac, 1.0f0))
|
spine = draw_grid_lines(sp, yspine_segs, 1f0, :solid, model, RGBA(yac, 1.0f0))
|
||||||
push!(axis_vis, spine)
|
push!(axis_vis, spine)
|
||||||
end
|
end
|
||||||
|
if sp[:framestyle] in (:zerolines, :grid)
|
||||||
|
if alpha(xaxis[:foreground_color_grid]) > 0
|
||||||
|
spine = draw_grid_lines(sp, xtick_segs, 1f0, :solid, model, RGBA(xgc, xaxis[:gridalpha]))
|
||||||
|
push!(axis_vis, spine)
|
||||||
|
end
|
||||||
|
if alpha(yaxis[:foreground_color_grid]) > 0
|
||||||
|
spine = draw_grid_lines(sp, ytick_segs, 1f0, :solid, model, RGBA(ygc, yaxis[:gridalpha]))
|
||||||
|
push!(axis_vis, spine)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if alpha(xaxis[:foreground_color_axis]) > 0
|
||||||
|
spine = draw_grid_lines(sp, xtick_segs, 1f0, :solid, model, RGBA(xac, 1.0f0))
|
||||||
|
push!(axis_vis, spine)
|
||||||
|
end
|
||||||
|
if alpha(yaxis[:foreground_color_axis]) > 0
|
||||||
|
spine = draw_grid_lines(sp, ytick_segs, 1f0, :solid, model, RGBA(yac, 1.0f0))
|
||||||
|
push!(axis_vis, spine)
|
||||||
|
end
|
||||||
|
end
|
||||||
fcolor = Plots.gl_color(xaxis[:foreground_color_axis])
|
fcolor = Plots.gl_color(xaxis[:foreground_color_axis])
|
||||||
|
|
||||||
xlim = Plots.axis_limits(xaxis)
|
xlim = Plots.axis_limits(xaxis)
|
||||||
|
|||||||
@ -760,7 +760,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
GR.setwindow(xmin, xmax, ymin, ymax)
|
GR.setwindow(xmin, xmax, ymin, ymax)
|
||||||
end
|
end
|
||||||
|
|
||||||
xticks, yticks, xspine_segs, yspine_segs, xgrid_segs, ygrid_segs, xborder_segs, yborder_segs = axis_drawing_info(sp)
|
xticks, yticks, xspine_segs, yspine_segs, xtick_segs, ytick_segs, xgrid_segs, ygrid_segs, xborder_segs, yborder_segs = axis_drawing_info(sp)
|
||||||
# @show xticks yticks #spine_segs grid_segs
|
# @show xticks yticks #spine_segs grid_segs
|
||||||
|
|
||||||
# draw the grid lines
|
# draw the grid lines
|
||||||
@ -787,6 +787,25 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
gr_polyline(coords(yspine_segs)...)
|
gr_polyline(coords(yspine_segs)...)
|
||||||
GR.setclip(1)
|
GR.setclip(1)
|
||||||
|
|
||||||
|
# axis ticks
|
||||||
|
if sp[:framestyle] in (:zerolines, :grid)
|
||||||
|
gr_set_line(1, :solid, xaxis[:foreground_color_grid])
|
||||||
|
GR.settransparency(xaxis[:gridalpha])
|
||||||
|
else
|
||||||
|
gr_set_line(1, :solid, xaxis[:foreground_color_axis])
|
||||||
|
end
|
||||||
|
GR.setclip(0)
|
||||||
|
gr_polyline(coords(xtick_segs)...)
|
||||||
|
if sp[:framestyle] in (:zerolines, :grid)
|
||||||
|
gr_set_line(1, :solid, yaxis[:foreground_color_grid])
|
||||||
|
GR.settransparency(yaxis[:gridalpha])
|
||||||
|
else
|
||||||
|
gr_set_line(1, :solid, yaxis[:foreground_color_axis])
|
||||||
|
end
|
||||||
|
GR.setclip(0)
|
||||||
|
gr_polyline(coords(ytick_segs)...)
|
||||||
|
GR.setclip(1)
|
||||||
|
|
||||||
# tick marks
|
# tick marks
|
||||||
if !(xticks in (:none, nothing, false))
|
if !(xticks in (:none, nothing, false))
|
||||||
# x labels
|
# x labels
|
||||||
|
|||||||
@ -971,14 +971,15 @@ function py_set_scale(ax, axis::Axis)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function py_set_axis_colors(ax, a::Axis)
|
function py_set_axis_colors(sp, ax, a::Axis)
|
||||||
for (loc, spine) in ax[:spines]
|
for (loc, spine) in ax[:spines]
|
||||||
spine[:set_color](py_color(a[:foreground_color_border]))
|
spine[:set_color](py_color(a[:foreground_color_border]))
|
||||||
end
|
end
|
||||||
axissym = Symbol(a[:letter], :axis)
|
axissym = Symbol(a[:letter], :axis)
|
||||||
if haskey(ax, axissym)
|
if haskey(ax, axissym)
|
||||||
|
tickcolor = sp[:framestyle] == :zerolines ? py_color(plot_color(a[:foreground_color_grid], a[:gridalpha])) : py_color(a[:foreground_color_axis])
|
||||||
ax[:tick_params](axis=string(a[:letter]), which="both",
|
ax[:tick_params](axis=string(a[:letter]), which="both",
|
||||||
colors=py_color(a[:foreground_color_axis]),
|
colors=tickcolor,
|
||||||
labelcolor=py_color(a[:foreground_color_text]))
|
labelcolor=py_color(a[:foreground_color_text]))
|
||||||
ax[axissym][:label][:set_color](py_color(a[:foreground_color_guide]))
|
ax[axissym][:label][:set_color](py_color(a[:foreground_color_guide]))
|
||||||
end
|
end
|
||||||
@ -1055,10 +1056,14 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
|
|||||||
ax[:spines]["bottom"][:set_position]("zero")
|
ax[:spines]["bottom"][:set_position]("zero")
|
||||||
ax[:spines]["left"][:set_position]("zero")
|
ax[:spines]["left"][:set_position]("zero")
|
||||||
end
|
end
|
||||||
elseif sp[:framestyle] in (:grid, :none, :origin)
|
elseif sp[:framestyle] in (:grid, :none, :zerolines)
|
||||||
for (loc, spine) in ax[:spines]
|
for (loc, spine) in ax[:spines]
|
||||||
spine[:set_visible](false)
|
spine[:set_visible](false)
|
||||||
end
|
end
|
||||||
|
if sp[:framestyle] == :zerolines
|
||||||
|
ax[:axhline](y = 0, color = py_color(sp[:xaxis][:foreground_color_axis]), lw = 0.75)
|
||||||
|
ax[:axvline](x = 0, color = py_color(sp[:yaxis][:foreground_color_axis]), lw = 0.75)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1102,7 +1107,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
|
|||||||
alpha = axis[:gridalpha])
|
alpha = axis[:gridalpha])
|
||||||
ax[:set_axisbelow](true)
|
ax[:set_axisbelow](true)
|
||||||
end
|
end
|
||||||
py_set_axis_colors(ax, axis)
|
py_set_axis_colors(sp, ax, axis)
|
||||||
end
|
end
|
||||||
|
|
||||||
# aspect ratio
|
# aspect ratio
|
||||||
|
|||||||
@ -365,7 +365,7 @@ function _expand_subplot_extrema(sp::Subplot, d::KW, st::Symbol)
|
|||||||
expand_extrema!(sp, d)
|
expand_extrema!(sp, d)
|
||||||
end
|
end
|
||||||
# expand for zerolines (axes through origin)
|
# expand for zerolines (axes through origin)
|
||||||
if sp[:framestyle] == :origin
|
if sp[:framestyle] in (:origin, :zerolines)
|
||||||
expand_extrema!(sp[:xaxis], 0.0)
|
expand_extrema!(sp[:xaxis], 0.0)
|
||||||
expand_extrema!(sp[:yaxis], 0.0)
|
expand_extrema!(sp[:yaxis], 0.0)
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user