diff --git a/src/arg_desc.jl b/src/arg_desc.jl index 136b1603..06f525bb 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -92,6 +92,7 @@ const _arg_desc = KW( :right_margin => "Measure (multiply by `mm`, `px`, etc) or `:match` (matches `:margin`). Specifies the extra padding to the right of the subplot.", :bottom_margin => "Measure (multiply by `mm`, `px`, etc) or `:match` (matches `:margin`). Specifies the extra padding on the bottom of the subplot.", :subplot_index => "Integer. Internal (not set by user). Specifies the index of this subplot in the Plot's `plt.subplot` list.", +:colorbar_title => "String. Title of colorbar.", # axis args :guide => "String. Axis guide (label).", diff --git a/src/args.jl b/src/args.jl index 2cdc5c89..5dbbc35b 100644 --- a/src/args.jl +++ b/src/args.jl @@ -248,6 +248,7 @@ const _subplot_defaults = KW( :right_margin => :match, :bottom_margin => :match, :subplot_index => -1, + :colorbar_title => "", ) const _axis_defaults = KW( diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 730d2437..2b3d923a 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -31,6 +31,7 @@ const _pyplot_attr = merge_with_base_supported([ :clims, :inset_subplots, :dpi, + :colorbar_title, ]) const _pyplot_seriestype = [ :path, :steppre, :steppost, :shape, @@ -810,7 +811,9 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) # note: the colorbar axis is positioned independently from the subplot axis fig = plt.o cbax = fig[:add_axes]([0.8,0.1,0.03,0.8], label = string(gensym())) - sp.attr[:cbar_handle] = fig[:colorbar](handle; cax = cbax, kw...) + cb = fig[:colorbar](handle; cax = cbax, kw...) + cb[:set_label](sp[:colorbar_title]) + sp.attr[:cbar_handle] = cb sp.attr[:cbar_ax] = cbax end @@ -1057,7 +1060,7 @@ function _update_min_padding!(sp::Subplot{PyPlotBackend}) # optionally add the width of colorbar labels and colorbar to rightpad if haskey(sp.attr, :cbar_ax) bb = py_bbox(sp.attr[:cbar_handle][:ax][:get_yticklabels]()) - sp.attr[:cbar_width] = _cbar_width + width(bb) + 1mm + sp.attr[:cbar_width] = _cbar_width + width(bb) + 1mm + (sp[:colorbar_title] == "" ? 0px : 30px) rightpad = rightpad + sp.attr[:cbar_width] end