diff --git a/src/arg_desc.jl b/src/arg_desc.jl index 69c40cd1..7b7e5283 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -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`.", diff --git a/src/args.jl b/src/args.jl index ef134731..6b106e8b 100644 --- a/src/args.jl +++ b/src/args.jl @@ -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) diff --git a/src/backends.jl b/src/backends.jl index 01226e78..26f01c91 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -229,7 +229,7 @@ const _base_supported_args = [ :subplot_index, :discrete_values, :projection, - + :show_empty_bins ] function merge_with_base_supported(v::AVec) diff --git a/src/examples.jl b/src/examples.jl index 5919d8a4..19b167ad 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -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)] ), ] diff --git a/src/recipes.jl b/src/recipes.jl index 1c3528e8..75736fda 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -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