discrete value fixes; margin args; check for fillrange in contourf; skip test 6

This commit is contained in:
Thomas Breloff 2016-05-23 18:15:33 -04:00
parent 0a00d1fbf3
commit 90e22f179e
5 changed files with 54 additions and 28 deletions

View File

@ -205,6 +205,11 @@ const _subplot_defaults = KW(
# :polar => false,
:projection => :none, # can also be :polar or :3d
:aspect_ratio => :none, # choose from :none or :equal
:margin => 2mm,
:left_margin => :match,
:top_margin => :match,
:right_margin => :match,
:bottom_margin => :match,
)
const _axis_defaults = KW(
@ -393,7 +398,7 @@ add_aliases(:aspect_ratio, :aspectratio, :axis_ratio, :axisratio, :ratio)
add_aliases(:match_dimensions, :transpose, :transpose_z)
add_aliases(:subplot, :sp, :subplt, :splt)
add_aliases(:projection, :proj)
add_aliases(:title_location, :title_loc, :titleloc)
add_aliases(:title_location, :title_loc, :titleloc, :title_position, :title_pos, :titlepos, :titleposition, :title_align, :title_alignment)
add_aliases(:series_annotations, :series_ann, :seriesann, :series_anns, :seriesanns, :series_annotation)
@ -955,6 +960,12 @@ function _update_subplot_args(plt::Plot, sp::Subplot, d_in::KW, subplot_index::I
color_or_match!(spargs, :foreground_color_grid, fg)
color_or_match!(spargs, :foreground_color_title, fg)
for k in (:left_margin, :top_margin, :right_margin, :bottom_margin)
if spargs[k] == :match
spargs[k] = spargs[:margin]
end
end
# info("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
# DD(spargs, "before loop")

View File

@ -10,8 +10,10 @@ function Axis(letter::Symbol, args...; kw...)
d = KW(
:letter => letter,
:extrema => (Inf, -Inf),
:discrete_map => Dict(), # map discrete values to continuous plot values
:discrete_values => Tuple{Float64,Any}[],
:discrete_map => Dict(), # map discrete values to discrete indices
# :discrete_values => Tuple{Float64,Any}[],
:discrete_values => [],
:continuous_values => zeros(0),
:use_minor => false,
:show => true, # show or hide the axis? (useful for linked subplots)
)
@ -89,7 +91,8 @@ function get_ticks(a::Axis)
ticks = a[:ticks]
dvals = a[:discrete_values]
if !isempty(dvals) && ticks == :auto
vals, labels = unzip(dvals)
# vals, labels = unzip(dvals)
a[:continuous_values], dvals
else
ticks
end
@ -114,20 +117,28 @@ end
# these methods track the discrete values which correspond to axis continuous values (cv)
# whenever we have discrete values, we automatically set the ticks to match.
# we return (continuous_value, discrete_index)
function discrete_value!(a::Axis, v)
cv_idx = get(a[:discrete_map], v, 0)
if cv_idx == 0
function discrete_value!(a::Axis, dv)
cv_idx = get(a[:discrete_map], dv, -1)
if cv_idx == -1
emin, emax = a[:extrema]
cv = max(0.5, emax + 1.0)
expand_extrema!(a, cv)
a[:discrete_map][v] = cv
push!(a[:discrete_values], (cv, v))
cv, length(a[:discrete_values])
push!(a[:discrete_values], dv)
push!(a[:continuous_values], cv)
cv_idx = length(a[:discrete_values])
a[:discrete_map][dv] = cv_idx
cv, cv_idx
else
a[:discrete_values][cv_idx][1], cv_idx
cv = a[:continuous_values][cv_idx]
cv, cv_idx
end
end
# continuous value... just pass back with a negative index
function discrete_value!(a::Axis, cv::Number)
cv, -1
end
# add the discrete value for each item. return the continuous values and the indices
function discrete_value!(a::Axis, v::AVec)
n = length(v)

View File

@ -461,7 +461,11 @@ function _update_min_padding!(sp::Subplot{PyPlotBackend})
# TODO: this should initialize to the margin from sp.attr
# figure out how much the axis components and title "stick out" from the plot area
leftpad = toppad = rightpad = bottompad = 1mm
# leftpad = toppad = rightpad = bottompad = 1mm
leftpad = sp.attr[:left_margin]
toppad = sp.attr[:top_margin]
rightpad = sp.attr[:right_margin]
bottompad = sp.attr[:bottom_margin]
for bb in (py_bbox_axis(ax, "x"), py_bbox_axis(ax, "y"), py_bbox_title(ax))
if ispositive(width(bb)) && ispositive(height(bb))
leftpad = max(leftpad, left(plotbb) - left(bb))
@ -717,15 +721,15 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series)
push!(handles, handle)
# contour fills
# if st == :contour
handle = ax[:contourf](x, y, z, levelargs...;
label = d[:label],
zorder = plt.n + 0.5,
cmap = pyfillcolormap(d),
extrakw...
)
push!(handles, handle)
# end
if d[:fillrange] != nothing
handle = ax[:contourf](x, y, z, levelargs...;
label = d[:label],
zorder = plt.n + 0.5,
cmap = pyfillcolormap(d),
extrakw...
)
push!(handles, handle)
end
end
if st in (:surface, :wireframe)
@ -837,13 +841,12 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series)
end
if st == :pie
handle = ax[:pie](y;
# label = d[:label],
# colors = # a vector of colors?
# labels = x
labels = if haskey(d,:x_discrete_indices)
dvals = sp.attr[:xaxis].d[:discrete_values]
[dvals[idx][2] for idx in d[:x_discrete_indices]]
[dvals[idx] for idx in d[:x_discrete_indices]]
else
d[:x]
end

View File

@ -119,10 +119,11 @@ function _apply_series_recipe(plt::Plot, d::KW)
axis = sp.attr[symbol(letter, "axis")]
if eltype(data) <: Number
expand_extrema!(axis, data)
else
elseif data != nothing
# TODO: need more here... gotta track the discrete reference value
# as well as any coord offset (think of boxplot shape coords... they all
# correspond to the same x-value)
# @show letter,eltype(data),typeof(data)
d[letter], d[symbol(letter,"_discrete_indices")] = discrete_value!(axis, data)
end
end

View File

@ -16,21 +16,21 @@ facts("Gadfly") do
@fact plot(sort(rand(10)), rand(Int, 10, 3)) --> not(nothing)
@fact plot!(rand(10,3), rand(10,3)) --> not(nothing)
image_comparison_facts(:gadfly, skip=[4,6,19,23,24,27], eps=img_eps)
image_comparison_facts(:gadfly, skip=[4,6,23,24,27], eps=img_eps)
end
facts("PyPlot") do
@fact pyplot() --> Plots.PyPlotBackend()
@fact backend() --> Plots.PyPlotBackend()
image_comparison_facts(:pyplot, skip=[19], eps=img_eps)
image_comparison_facts(:pyplot, skip=[6], eps=img_eps)
end
facts("GR") do
@fact gr() --> Plots.GRBackend()
@fact backend() --> Plots.GRBackend()
@linux_only image_comparison_facts(:gr, skip=[24], eps=img_eps)
@linux_only image_comparison_facts(:gr, skip=[6,24], eps=img_eps)
end
facts("Plotly") do