From f901254519a7ea202c7be032acd1aa0c16acee8b Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 28 Feb 2018 21:19:18 +0100 Subject: [PATCH] add contour_labels attribute and minor GR contour fixes --- src/arg_desc.jl | 1 + src/args.jl | 2 ++ src/backends/gr.jl | 12 ++++++++---- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/arg_desc.jl b/src/arg_desc.jl index 386639b6..199190db 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -43,6 +43,7 @@ const _arg_desc = KW( :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.", :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`.", :subplot => "Integer (subplot index) or Subplot object. The subplot that this series belongs to.", :series_annotations => "AbstractVector of String or PlotText. These are annotations which are mapped to data points/positions.", diff --git a/src/args.jl b/src/args.jl index 808822b3..0a06b64a 100644 --- a/src/args.jl +++ b/src/args.jl @@ -272,6 +272,7 @@ const _series_defaults = KW( :normalize => false, # do we want a normalized histogram? :weights => nothing, # optional weights for histograms (1D and 2D) :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 # this ONLY effects whether or not the z-matrix is transposed for a heatmap display! :subplot => :auto, # which subplot(s) does this series belong to? @@ -574,6 +575,7 @@ add_aliases(:gridstyle, :grid_style, :gridlinestyle, :grid_linestyle, :grid_ls, add_aliases(:framestyle, :frame_style, :frame, :axesstyle, :axes_style, :boxstyle, :box_style, :box, :borderstyle, :border_style, :border) add_aliases(:tick_direction, :tickdirection, :tick_dir, :tickdir, :tick_orientation, :tickorientation, :tick_or, :tickor) add_aliases(:camera, :cam, :viewangle, :view_angle) +add_aliases(:contour_labels, :contourlabels, :clabels, :clabs) # add all pluralized forms to the _keyAliases dict for arg in keys(_series_defaults) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index e49dd6b2..8d2d49da 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -1055,24 +1055,28 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) elseif st == :contour zmin, zmax = clims GR.setspace(zmin, zmax, 0, 90) - if typeof(series[:levels]) <: Array + if typeof(series[:levels]) <: AbstractArray h = series[:levels] else - h = linspace(zmin, zmax, series[:levels]) + h = series[:levels] > 1 ? linspace(zmin, zmax, series[:levels]) : [(zmin + zmax) / 2] end if series[:fillrange] != nothing GR.surface(x, y, z, GR.OPTION_CELL_ARRAY) else GR.setlinetype(gr_linetype[series[:linestyle]]) GR.setlinewidth(max(0, series[:linewidth] / (sum(gr_plot_size) * 0.001))) - GR.contour(x, y, h, z, 1000) + if plot_color(series[:linecolor]) == plot_color(:black) + GR.contour(x, y, h, z, 0 + (series[:contour_labels] == true ? 1 : 0)) + else + GR.contour(x, y, h, z, 1000 + (series[:contour_labels] == true ? 1 : 0)) + end end # create the colorbar of contour levels if cmap gr_set_line(1, :solid, yaxis[:foreground_color_axis]) gr_set_viewport_cmap(sp) - l = round.(Int32, 1000 + (h - ignorenan_minimum(h)) / (ignorenan_maximum(h) - ignorenan_minimum(h)) * 255) + l = (length(h) > 1) ? round.(Int32, 1000 + (h - ignorenan_minimum(h)) / (ignorenan_maximum(h) - ignorenan_minimum(h)) * 255) : 1000 GR.setwindow(xmin, xmax, zmin, zmax) GR.cellarray(xmin, xmax, zmax, zmin, 1, length(l), l) ztick = 0.5 * GR.tick(zmin, zmax)