diff --git a/src/arg_desc.jl b/src/arg_desc.jl index 13e42645..7d501762 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 6f719bae..769bf76d 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 @@ -574,6 +575,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, :show_zeros, :showzeros) 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 8cb4c0ce..80953dd0 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -234,7 +234,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 6dd1b7f4..f328f7df 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -129,6 +129,16 @@ PlotExample("Histogram2D", 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)] +), + PlotExample("Line types", "", [:(begin diff --git a/src/recipes.jl b/src/recipes.jl index ca2468e1..fa29f0c4 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -755,12 +755,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