working on axis limit fixes

This commit is contained in:
Thomas Breloff 2016-06-02 20:22:58 -05:00
parent 6c7b113de5
commit 32e816b713
5 changed files with 94 additions and 36 deletions

View File

@ -165,7 +165,7 @@ const _series_defaults = KW(
:levels => 15,
:orientation => :vertical,
:bar_position => :overlay, # for bar plots and histograms: could also be stack (stack up) or dodge (side by side)
:bar_width => 0.8,
:bar_width => nothing,
:bar_edges => false,
:xerror => nothing,
:yerror => nothing,

View File

@ -130,6 +130,58 @@ function expand_extrema!{N<:Number}(axis::Axis, v::AVec{N})
ex
end
function expand_extrema!(sp::Subplot, d::KW)
# first expand for the data
for letter in (:x, :y, :z)
data = d[letter]
axis = sp.attr[Symbol(letter, "axis")]
if eltype(data) <: Number
expand_extrema!(axis, data)
elseif isa(data, Surface) && eltype(data.surf) <: Number
expand_extrema!(axis, data)
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
# # expand for fillrange/bar_width
# fillaxis, baraxis = sp.attr[:yaxis], sp.attr[:xaxis]
# if isvertical(d)
# fillaxis, baraxis = baraxis, fillaxis
# end
# expand for fillrange
vert = isvertical(d)
fr = d[:fillrange]
if fr == nothing && d[:seriestype] == :bar
fr = 0.0
end
expand_extrema!(sp.attr[vert ? :yaxis : :xaxis], fr)
# @show d[:fillrange] d[:bar_width]
# expand for bar_width
if d[:seriestype] == :bar
dsym = vert ? :x : :y
data = d[dsym]
bw = d[:bar_width]
if bw == nothing
bw = d[:bar_width] = mean(diff(data))
end
@show data bw
axis = sp.attr[Symbol(dsym, :axis)]
expand_extrema!(axis, maximum(data) + 0.5maximum(bw))
expand_extrema!(axis, minimum(data) - 0.5minimum(bw))
end
end
# -------------------------------------------------------------------------
# push the limits out slightly

View File

@ -633,14 +633,14 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
for axis_idx = 1:num_axes
xmin, xmax, ymin, ymax = extrema[axis_idx,:]
if scale & GR.OPTION_X_LOG == 0
xmin, xmax = GR.adjustlimits(xmin, xmax)
# xmin, xmax = GR.adjustlimits(xmin, xmax)
majorx = 5
xtick = GR.tick(xmin, xmax) / majorx
else
xtick = majorx = 1
end
if scale & GR.OPTION_Y_LOG == 0
ymin, ymax = GR.adjustlimits(ymin, ymax)
# ymin, ymax = GR.adjustlimits(ymin, ymax)
majory = 5
ytick = GR.tick(ymin, ymax) / majory
else

View File

@ -40,7 +40,7 @@ supportedArgs(::PyPlotBackend) = [
supportedAxes(::PyPlotBackend) = _allAxes
supportedTypes(::PyPlotBackend) = [
:none, :line, :path, :steppre, :steppost, :shape,
:scatter, :histogram2d, :hexbin, :histogram, :density,
:scatter, :histogram2d, :hexbin, #:histogram, #:density,
:bar, :sticks, #:box, :violin, :quiver,
:hline, :vline, :heatmap, :pie, :image,
:contour, :contour3d, :path3d, :scatter3d, :surface, :wireframe
@ -507,7 +507,11 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series)
end
if st == :bar
extrakw[isvertical(d) ? :width : :height] = d[:bar_width]
bw = d[:bar_width]
if bw == nothing
bw = mean(diff(isvertical(d) ? x : y))
end
extrakw[isvertical(d) ? :width : :height] = bw
fr = get(d, :fillrange, nothing)
if fr != nothing
extrakw[:bottom] = fr
@ -568,21 +572,21 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series)
push!(handles, handle)
end
if st == :histogram
handle = ax[:hist](y;
label = d[:label],
zorder = plt.n,
color = pyfillcolor(d),
edgecolor = pylinecolor(d),
linewidth = d[:linewidth],
bins = d[:bins],
normed = d[:normalize],
weights = d[:weights],
orientation = (isvertical(d) ? "vertical" : "horizontal"),
histtype = (d[:bar_position] == :stack ? "barstacked" : "bar")
)[3]
push!(handles, handle)
end
# if st == :histogram
# handle = ax[:hist](y;
# label = d[:label],
# zorder = plt.n,
# color = pyfillcolor(d),
# edgecolor = pylinecolor(d),
# linewidth = d[:linewidth],
# bins = d[:bins],
# normed = d[:normalize],
# weights = d[:weights],
# orientation = (isvertical(d) ? "vertical" : "horizontal"),
# histtype = (d[:bar_position] == :stack ? "barstacked" : "bar")
# )[3]
# push!(handles, handle)
# end
if st == :histogram2d
handle = ax[:hist2d](x, y;

View File

@ -171,24 +171,26 @@ function _apply_series_recipe(plt::Plot, d::KW)
end
# adjust extrema and discrete info
if st != :image
for letter in (:x, :y, :z)
data = d[letter]
axis = sp.attr[Symbol(letter, "axis")]
if eltype(data) <: Number
expand_extrema!(axis, data)
elseif isa(data, Surface) && eltype(data.surf) <: Number
expand_extrema!(axis, data)
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
if !(st in (:image, :histogram, :histogram2d))
expand_extrema!(sp, d)
# for letter in (:x, :y, :z)
# data = d[letter]
# axis = sp.attr[Symbol(letter, "axis")]
# if eltype(data) <: Number
# expand_extrema!(axis, data)
# elseif isa(data, Surface) && eltype(data.surf) <: Number
# expand_extrema!(axis, data)
# 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
end
# add the series!
warnOnUnsupportedArgs(plt.backend, d)
warnOnUnsupported(plt.backend, d)