Merge pull request #2062 from yha/show-empty-bins

Series attribute to show empty bins as 0.
This commit is contained in:
Daniel Schwabeneder 2019-10-13 20:15:50 +02:00 committed by GitHub
commit 76c7d9dc89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 9 deletions

View File

@ -42,6 +42,7 @@ const _arg_desc = KW(
:arrow => "nothing (no arrows), Bool (if true, default arrows), Arrow object, or arg(s) that could be style or head length/widths. Defines arrowheads that should be displayed at the end of path line segments (just before a NaN and the last non-NaN point). Used in quiverplot, streamplot, or similar.",
:normalize => "Bool or Symbol. Histogram normalization mode. Possible values are: false/:none (no normalization, default), true/:pdf (normalize to a discrete Probability Density Function, where the total area of the bins is 1), :probability (bin heights sum to 1) and :density (the area of each bin, rather than the height, is equal to the counts - useful for uneven bin sizes).",
:weights => "AbstractVector. Used in histogram types for weighted counts.",
:show_empty_bins => "Bool. Whether empty bins in a 2D histogram are colored as 0 (true), or transparent (the default).",
:contours => "Bool. Add contours to the side-grids of 3D plots? Used in surface/wireframe.",
:contour_labels => "Bool. Show labels at the contour lines?",
:match_dimensions => "Bool. For heatmap types... should the first dimension of a matrix (rows) correspond to the first dimension of the plot (x-axis)? The default is false, which matches the behavior of Matplotlib, Plotly, and others. Note: when passing a function for z, the function should still map `(x,y) -> z`.",

View File

@ -272,6 +272,7 @@ const _series_defaults = KW(
:arrow => nothing, # allows for adding arrows to line/path... call `arrow(args...)`
:normalize => false, # do we want a normalized histogram?
:weights => nothing, # optional weights for histograms (1D and 2D)
:show_empty_bins => false, # should empty bins in 2D histogram be colored as zero (otherwise they are transparent)
:contours => false, # add contours to 3d surface and wireframe plots
:contour_labels => false,
:match_dimensions => false, # do rows match x (true) or y (false) for heatmap/image/spy? see issue 196
@ -581,6 +582,7 @@ add_aliases(:xerror, :xerr, :xerrorbar)
add_aliases(:yerror, :yerr, :yerrorbar, :err, :errorbar)
add_aliases(:quiver, :velocity, :quiver2d, :gradient, :vectorfield)
add_aliases(:normalize, :norm, :normed, :normalized)
add_aliases(:show_empty_bins, :showemptybins, :showempty, :show_empty)
add_aliases(:aspect_ratio, :aspectratio, :axis_ratio, :axisratio, :ratio)
add_aliases(:match_dimensions, :transpose, :transpose_z)
add_aliases(:subplot, :sp, :subplt, :splt)

View File

@ -229,7 +229,7 @@ const _base_supported_args = [
:subplot_index,
:discrete_values,
:projection,
:show_empty_bins
]
function merge_with_base_supported(v::AVec)

View File

@ -467,8 +467,17 @@ PlotExample("Ribbons",
plot(0:10; ribbon = sqrt),
plot(0:10; ribbon = 1),
)
end)
]
end)]
),
PlotExample("Histogram2D (complex values)",
"",
[:(begin
n = 10_000
x = exp.(0.1randn(n) .+ randn(n).*(im))
histogram2d(x, nbins=(20,40), show_empty_bins=true,
normed=true, aspect_ratio=1)
end)]
),
]

View File

@ -746,12 +746,14 @@ end
edge_x, edge_y, weights = x, y, z.surf
float_weights = float(weights)
if float_weights === weights
float_weights = deepcopy(float_weights)
end
for (i, c) in enumerate(float_weights)
if c == 0
float_weights[i] = NaN
if !plotattributes[:show_empty_bins]
if float_weights === weights
float_weights = deepcopy(float_weights)
end
for (i, c) in enumerate(float_weights)
if c == 0
float_weights[i] = NaN
end
end
end