added clims attribute and support it in pyplot

This commit is contained in:
Thomas Breloff 2016-06-10 01:25:34 -04:00
parent 8007d0dd6a
commit cf4d78c87c
3 changed files with 49 additions and 4 deletions

View File

@ -74,6 +74,7 @@ const _arg_desc = KW(
:color_palette => "Vector of colors (cycle through) or color gradient (generate list from gradient) or `:auto` (generate a color list using `Colors.distiguishable_colors` and custom seed colors chosen to contrast with the background). The color palette is a color list from which series colors are automatically chosen.",
:legend => "Bool (show the legend?) or Symbol (legend position). Symbol values: `:none`, `:best`, `:right`, `:left`, `:top`, `:bottom`, `:inside`, `:legend`, `:topright`, `:topleft`, `:bottomleft`, `:bottomright` (note: only some may be supported in each backend)",
:colorbar => "Bool (show the colorbar?) or Symbol (colorbar position). Symbol values: `:none`, `:best`, `:right`, `:left`, `:top`, `:bottom`, `:legend` (matches legend value) (note: only some may be supported in each backend)",
:clims => "`:auto` or NTuple{2,Number}. Fixes the limits of the colorbar.",
:legendfont => "Font. Font of legend items.",
:grid => "Bool. Show the grid lines?",
:annotations => "(x,y,text) tuple(s). Can be a single tuple or a list of them. Text can be String or PlotText (created with `text(args...)`) Add one-off text annotations at the x,y coordinates.",

View File

@ -214,6 +214,7 @@ const _subplot_defaults = KW(
:color_palette => :auto,
:legend => :best,
:colorbar => :legend,
:clims => :auto,
:legendfont => font(8),
:grid => true,
:annotations => [], # annotation tuples... list of (x,y,annotation)
@ -388,6 +389,7 @@ add_aliases(:zticks, :ztick)
add_aliases(:zrotation, :zrot, :zr)
add_aliases(:legend, :leg, :key)
add_aliases(:colorbar, :cb, :cbar, :colorkey)
add_aliases(:clims, :clim, :cbarlims, :cbar_lims, :climits, :color_limits)
add_aliases(:smooth, :regression, :reg)
add_aliases(:levels, :nlevels, :nlev, :levs)
add_aliases(:size, :windowsize, :wsize)

View File

@ -36,6 +36,7 @@ supportedArgs(::PyPlotBackend) = [
:normalize, :weights, :contours, :aspect_ratio,
:match_dimensions,
:subplot,
:clims,
]
supportedAxes(::PyPlotBackend) = _allAxes
supportedTypes(::PyPlotBackend) = [
@ -502,6 +503,11 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series)
else
extrakw[:c] = convert(Vector{Float64}, d[:marker_z])
extrakw[:cmap] = pymarkercolormap(d)
clims = sp[:clims]
if isa(clims, Tuple) && length(clims) == 2
isfinite(clims[1]) && (extrakw[:vmin] = clims[1])
isfinite(clims[2]) && (extrakw[:vmax] = clims[2])
end
needs_colorbar = true
end
xyargs = if st in (:bar, :sticks) && !isvertical(d)
@ -546,13 +552,19 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series)
end
if st == :histogram2d
clims = sp[:clims]
if isa(clims, Tuple) && length(clims) == 2
isfinite(clims[1]) && (extrakw[:vmin] = clims[1])
isfinite(clims[2]) && (extrakw[:vmax] = clims[2])
end
handle = ax[:hist2d](x, y;
label = d[:label],
zorder = plt.n,
bins = d[:bins],
normed = d[:normalize],
weights = d[:weights],
cmap = pyfillcolormap(d) # applies to the pcolorfast object
cmap = pyfillcolormap(d), # applies to the pcolorfast object
extrakw...
)[4]
push!(handles, handle)
needs_colorbar = true
@ -565,13 +577,19 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series)
end
if st == :hexbin
clims = sp[:clims]
if isa(clims, Tuple) && length(clims) == 2
isfinite(clims[1]) && (extrakw[:vmin] = clims[1])
isfinite(clims[2]) && (extrakw[:vmax] = clims[2])
end
handle = ax[:hexbin](x, y;
label = d[:label],
zorder = plt.n,
gridsize = d[:bins],
linewidths = d[:linewidth],
edgecolors = pylinecolor(d),
cmap = pyfillcolormap(d) # applies to the pcolorfast object
cmap = pyfillcolormap(d), # applies to the pcolorfast object
extrakw...
)
push!(handles, handle)
needs_colorbar = true
@ -594,6 +612,11 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series)
z = transpose_z(d, z.surf)
needs_colorbar = true
clims = sp[:clims]
if isa(clims, Tuple) && length(clims) == 2
isfinite(clims[1]) && (extrakw[:vmin] = clims[1])
isfinite(clims[2]) && (extrakw[:vmax] = clims[2])
end
if st == :contour3d
extrakw[:extend3d] = true
@ -635,6 +658,11 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series)
if d[:marker_z] != nothing
extrakw[:facecolors] = getPyPlotCustomShading(d[:fillcolor], d[:marker_z], d[:fillalpha])
extrakw[:shade] = false
clims = sp[:clims]
if isa(clims, Tuple) && length(clims) == 2
isfinite(clims[1]) && (extrakw[:vmin] = clims[1])
isfinite(clims[2]) && (extrakw[:vmax] = clims[2])
end
else
extrakw[:cmap] = pyfillcolormap(d)
needs_colorbar = true
@ -672,12 +700,18 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series)
elseif typeof(z) <: AbstractVector
# tri-surface plot (http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#tri-surface-plots)
clims = sp[:clims]
if isa(clims, Tuple) && length(clims) == 2
isfinite(clims[1]) && (extrakw[:vmin] = clims[1])
isfinite(clims[2]) && (extrakw[:vmax] = clims[2])
end
handle = ax[:plot_trisurf](x, y, z;
label = d[:label],
zorder = plt.n,
cmap = pyfillcolormap(d),
linewidth = d[:linewidth],
edgecolor = pylinecolor(d)
edgecolor = pylinecolor(d),
extrakw...
)
push!(handles, handle)
needs_colorbar = true
@ -719,11 +753,19 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series)
if !isempty(dvals)
discrete_colorbar_values = dvals
end
clims = sp[:clims]
if isa(clims, Tuple) && length(clims) == 2
isfinite(clims[1]) && (extrakw[:vmin] = clims[1])
isfinite(clims[2]) && (extrakw[:vmax] = clims[2])
end
handle = ax[:pcolormesh](x, y, z;
label = d[:label],
zorder = plt.n,
cmap = pyfillcolormap(d),
edgecolors = (d[:linewidth] > 0 ? pylinecolor(d) : "face")
edgecolors = (d[:linewidth] > 0 ? pylinecolor(d) : "face"),
extrakw...
)
push!(handles, handle)
needs_colorbar = true