Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 233f4d4465 |
@@ -3,53 +3,14 @@
|
||||
|
||||
#### notes on release changes, ongoing development, and future planned work
|
||||
|
||||
- All new development should target 0.13!
|
||||
- All new development should target 0.12!
|
||||
- Minor version 0.11 is the last one to support Julia 0.5!!
|
||||
- Critical bugfixes only
|
||||
- `backports` branch is for Julia 0.5
|
||||
- `backports` branch is for Julia 0.4
|
||||
|
||||
---
|
||||
## (current master)
|
||||
|
||||
## 0.13.0
|
||||
|
||||
- support `plotattributes` rather than `d` in recipes
|
||||
- no longer export `w`, `h` and names from Measures.jl; use `using Plots.PlotMeasures` to get these names back
|
||||
- `bar_width` now depends on the minimum distance between bars, not the mean
|
||||
- better automatic x axis limits for plotting Functions
|
||||
- `tick_direction` attribute now allows ticks to be on the inside of the plot border
|
||||
- removed a bug where `p1 = plot(randn(10)); plot(p1, p2)` made `display(p1)` impossible
|
||||
- allow `plot([])` to generate an empty plot
|
||||
- add `origin` framestyle
|
||||
- ensure finite bin number on histograms with only one unique value
|
||||
- better automatic histogram bins for 2d histograms
|
||||
- more informative error message on passing unsupported seriestype in a recipe
|
||||
- allow grouping in user recipes
|
||||
- GR now has `line_z` and `fill_z` attributes for determining the color of shapes and lines
|
||||
- change GR default view angle for 3D plots to match that of PyPlot
|
||||
- fix `clims` on GR
|
||||
- fix `marker_z` for plotly backend
|
||||
- implement `framestyle` for plotly
|
||||
- fix logscale bug error for values < 1e-16 on pyplot
|
||||
- fix an issue on pyplot where >1 colorbar would be shown if there was >1 series
|
||||
- fix `writemime` for eps
|
||||
|
||||
## 0.12.4
|
||||
|
||||
- added a new `framestyle` argument with choices: :box, :semi, :axes, :grid and :none
|
||||
- changed the default bar width to 0.8
|
||||
- added working ribbon to plotly backend
|
||||
- ensure that automatic ticks always generate 4 to 8 ticks
|
||||
- group now groups keyword arguments of the same length as the input
|
||||
- allow passing DateTime objects as ticks
|
||||
- allow specifying the number of ticks as an integre
|
||||
- fix bug on errorbars in gr
|
||||
- fixed some but not all world age issues
|
||||
- better margin with room for text
|
||||
- added a `match` option for linecolor
|
||||
- better error message un unsupported series types
|
||||
- add a 'stride' keyword for the pyplot backend
|
||||
|
||||
## 0.12.3
|
||||
|
||||
- new grid line style defaults
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
julia 0.6
|
||||
|
||||
RecipesBase 0.2.3
|
||||
RecipesBase 0.2.0
|
||||
PlotUtils 0.4.1
|
||||
PlotThemes 0.1.3
|
||||
Reexport
|
||||
|
||||
+1
-7
@@ -1,4 +1,4 @@
|
||||
__precompile__(false)
|
||||
__precompile__(true)
|
||||
|
||||
module Plots
|
||||
|
||||
@@ -133,17 +133,11 @@ ignorenan_extrema(x) = Base.extrema(x)
|
||||
|
||||
# ---------------------------------------------------------
|
||||
|
||||
import Measures
|
||||
module PlotMeasures
|
||||
import Measures
|
||||
import Measures: Length, AbsoluteLength, Measure, BoundingBox, mm, cm, inch, pt, width, height, w, h
|
||||
const BBox = Measures.Absolute2DBox
|
||||
export BBox, BoundingBox, mm, cm, inch, pt, px, pct, w, h
|
||||
end
|
||||
|
||||
using .PlotMeasures
|
||||
import .PlotMeasures: Length, AbsoluteLength, Measure, width, height
|
||||
export BBox, BoundingBox
|
||||
# ---------------------------------------------------------
|
||||
|
||||
include("types.jl")
|
||||
|
||||
+2
-3
@@ -21,7 +21,7 @@ const _arg_desc = KW(
|
||||
:markerstrokewidth => "Number. Width of the marker stroke (border. in pixels)",
|
||||
:markerstrokecolor => "Color Type. Color of the marker stroke (border). `:match` will take the value from `:foreground_color_subplot`.",
|
||||
:markerstrokealpha => "Number in [0,1]. The alpha/opacity override for the marker stroke (border). `nothing` (the default) means it will take the alpha value of markerstrokecolor.",
|
||||
:bins => "Integer, NTuple{2,Integer}, AbstractVector or Symbol. Default is :auto (the Freedman-Diaconis rule). For histogram-types, defines the approximate number of bins to aim for, or the auto-binning algorithm to use (:sturges, :sqrt, :rice, :scott or :fd). For fine-grained control pass a Vector of break values, e.g. `linspace(extrema(x)..., 25)`",
|
||||
:bins => "Integer, NTuple{2,Integer}, AbstractVector or Symbol. Default is :auto. For histogram-types, defines the approximate number of bins to aim for, or the auto-binning algorithm to use (:sturges, :sqrt, :rice, :scott or :fd). For fine-grained control pass a Vector of break values, e.g. `linspace(extrema(x)..., 25)`",
|
||||
:smooth => "Bool. Add a regression line?",
|
||||
:group => "AbstractVector. Data is split into a separate series, one for each unique value in `group`.",
|
||||
:x => "Various. Input data. First Dimension",
|
||||
@@ -40,7 +40,7 @@ const _arg_desc = KW(
|
||||
:ribbon => "Number or AbstractVector. Creates a fillrange around the data points.",
|
||||
:quiver => "AbstractVector or 2-Tuple of vectors. The directional vectors U,V which specify velocity/gradient vectors for a quiver plot.",
|
||||
: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).",
|
||||
:normalize => "Bool or Symbol. Histogram normalization mode. Possible values are: false/:none (no normalization, default), true/:pdf (normalize to a PDF with integral of 1) and :density (only normalize in respect to 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.",
|
||||
: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`.",
|
||||
@@ -115,5 +115,4 @@ const _arg_desc = KW(
|
||||
:gridalpha => "Number in [0,1]. The alpha/opacity override for the grid lines.",
|
||||
:gridstyle => "Symbol. Style of the grid lines. Choose from $(_allStyles)",
|
||||
:gridlinewidth => "Number. Width of the grid lines (in pixels)",
|
||||
:tick_direction => "Symbol. Direction of the ticks. `:in` or `:out`"
|
||||
)
|
||||
|
||||
+6
-20
@@ -80,13 +80,9 @@ const _typeAliases = Dict{Symbol,Symbol}(
|
||||
|
||||
add_non_underscore_aliases!(_typeAliases)
|
||||
|
||||
const _histogram_like = [:histogram, :barhist, :barbins]
|
||||
const _line_like = [:line, :path, :steppre, :steppost]
|
||||
const _surface_like = [:contour, :contourf, :contour3d, :heatmap, :surface, :wireframe, :image]
|
||||
|
||||
like_histogram(seriestype::Symbol) = seriestype in _histogram_like
|
||||
like_line(seriestype::Symbol) = seriestype in _line_like
|
||||
like_surface(seriestype::Symbol) = seriestype in _surface_like
|
||||
like_histogram(seriestype::Symbol) = seriestype in (:histogram, :barhist, :barbins)
|
||||
like_line(seriestype::Symbol) = seriestype in (:line, :path, :steppre, :steppost)
|
||||
like_surface(seriestype::Symbol) = seriestype in (:contour, :contourf, :contour3d, :heatmap, :surface, :wireframe, :image)
|
||||
|
||||
is3d(seriestype::Symbol) = seriestype in _3dTypes
|
||||
is3d(series::Series) = is3d(series.d)
|
||||
@@ -185,7 +181,7 @@ function hasgrid(arg::Symbol, letter)
|
||||
end
|
||||
hasgrid(arg::AbstractString, letter) = hasgrid(Symbol(arg), letter)
|
||||
|
||||
const _allFramestyles = [:box, :semi, :axes, :origin, :zerolines, :grid, :none]
|
||||
const _allFramestyles = [:box, :semi, :axes, :grid, :none]
|
||||
const _framestyleAliases = Dict{Symbol, Symbol}(
|
||||
:frame => :box,
|
||||
:border => :box,
|
||||
@@ -193,8 +189,6 @@ const _framestyleAliases = Dict{Symbol, Symbol}(
|
||||
:transparent => :semi,
|
||||
:semitransparent => :semi,
|
||||
)
|
||||
|
||||
const _bar_width = 0.8
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
const _series_defaults = KW(
|
||||
@@ -246,7 +240,6 @@ const _series_defaults = KW(
|
||||
:primary => true, # when true, this "counts" as a series for color selection, etc. the main use is to allow
|
||||
# one logical series to be broken up (path and markers, for example)
|
||||
:hover => nothing, # text to display when hovering over the data points
|
||||
:stride => (1,1), # array stride for wireframe/surface, the first element is the row stride and the second is the column stride.
|
||||
)
|
||||
|
||||
|
||||
@@ -322,7 +315,6 @@ const _axis_defaults = KW(
|
||||
:gridalpha => 0.1,
|
||||
:gridstyle => :solid,
|
||||
:gridlinewidth => 0.5,
|
||||
:tick_direction => :in,
|
||||
)
|
||||
|
||||
const _suppress_warnings = Set{Symbol}([
|
||||
@@ -508,11 +500,10 @@ add_aliases(:series_annotations, :series_ann, :seriesann, :series_anns, :seriesa
|
||||
add_aliases(:html_output_format, :format, :fmt, :html_format)
|
||||
add_aliases(:orientation, :direction, :dir)
|
||||
add_aliases(:inset_subplots, :inset, :floating)
|
||||
add_aliases(:stride, :wirefame_stride, :surface_stride, :surf_str, :str)
|
||||
add_aliases(:gridlinewidth, :gridwidth, :grid_linewidth, :grid_width, :gridlw, :grid_lw)
|
||||
add_aliases(:gridstyle, :grid_style, :gridlinestyle, :grid_linestyle, :grid_ls, :gridls)
|
||||
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 all pluralized forms to the _keyAliases dict
|
||||
for arg in keys(_series_defaults)
|
||||
@@ -1281,8 +1272,6 @@ end
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
has_black_border_for_default(st) = error("The seriestype attribute only accepts Symbols, you passed the $(typeof(st)) $st.")
|
||||
has_black_border_for_default(st::Function) = error("The seriestype attribute only accepts Symbols, you passed the function $st.")
|
||||
function has_black_border_for_default(st::Symbol)
|
||||
like_histogram(st) || st in (:hexbin, :bar, :shape)
|
||||
end
|
||||
@@ -1372,16 +1361,13 @@ function _add_defaults!(d::KW, plt::Plot, sp::Subplot, commandIndex::Int)
|
||||
getSeriesRGBColor(d[:markerstrokecolor], d[:markerstrokealpha], sp, plotIndex)
|
||||
end
|
||||
|
||||
# if marker_z, fill_z or line_z are set, ensure we have a gradient
|
||||
# if marker_z or line_z are set, ensure we have a gradient
|
||||
if d[:marker_z] != nothing
|
||||
ensure_gradient!(d, :markercolor, :markeralpha)
|
||||
end
|
||||
if d[:line_z] != nothing
|
||||
ensure_gradient!(d, :linecolor, :linealpha)
|
||||
end
|
||||
if d[:fill_z] != nothing
|
||||
ensure_gradient!(d, :fillcolor, :fillalpha)
|
||||
end
|
||||
|
||||
# scatter plots don't have a line, but must have a shape
|
||||
if d[:seriestype] in (:scatter, :scatterbins, :scatterhist, :scatter3d)
|
||||
|
||||
+10
-42
@@ -365,7 +365,7 @@ function expand_extrema!(sp::Subplot, d::KW)
|
||||
|
||||
bw = d[:bar_width]
|
||||
if bw == nothing
|
||||
bw = d[:bar_width] = _bar_width * ignorenan_minimum(filter(x->x>0,diff(sort(data))))
|
||||
bw = d[:bar_width] = ignorenan_mean(diff(data))
|
||||
end
|
||||
axis = sp.attr[Symbol(dsym, :axis)]
|
||||
expand_extrema!(axis, ignorenan_maximum(data) + 0.5maximum(bw))
|
||||
@@ -508,8 +508,6 @@ function axis_drawing_info(sp::Subplot)
|
||||
yticks = get_ticks(yaxis)
|
||||
xaxis_segs = Segments(2)
|
||||
yaxis_segs = Segments(2)
|
||||
xtick_segs = Segments(2)
|
||||
ytick_segs = Segments(2)
|
||||
xgrid_segs = Segments(2)
|
||||
ygrid_segs = Segments(2)
|
||||
xborder_segs = Segments(2)
|
||||
@@ -517,67 +515,37 @@ function axis_drawing_info(sp::Subplot)
|
||||
|
||||
if !(sp[:framestyle] == :none)
|
||||
# xaxis
|
||||
sp[:framestyle] in (:grid, :origin, :zerolines) || push!(xaxis_segs, (xmin,ymin), (xmax,ymin)) # bottom spine / xaxis
|
||||
if sp[:framestyle] in (:origin, :zerolines)
|
||||
push!(xaxis_segs, (xmin, 0.0), (xmax, 0.0))
|
||||
# don't show the 0 tick label for the origin framestyle
|
||||
if sp[:framestyle] == :origin && length(xticks) > 1
|
||||
showticks = xticks[1] .!= 0
|
||||
xticks = (xticks[1][showticks], xticks[2][showticks])
|
||||
end
|
||||
end
|
||||
sp[:framestyle] == :grid || push!(xaxis_segs, (xmin,ymin), (xmax,ymin)) # bottom spine / xaxis
|
||||
sp[:framestyle] in (:semi, :box) && push!(xborder_segs, (xmin,ymax), (xmax,ymax)) # top spine
|
||||
if !(xaxis[:ticks] in (nothing, false))
|
||||
f = scalefunc(yaxis[:scale])
|
||||
invf = invscalefunc(yaxis[:scale])
|
||||
ticks_in = xaxis[:tick_direction] == :out ? -1 : 1
|
||||
t1 = invf(f(ymin) + 0.015 * (f(ymax) - f(ymin)) * ticks_in)
|
||||
t2 = invf(f(ymax) - 0.015 * (f(ymax) - f(ymin)) * ticks_in)
|
||||
t3 = invf(f(0) + 0.015 * (f(ymax) - f(ymin)) * ticks_in)
|
||||
t1 = invf(f(ymin) + 0.015*(f(ymax)-f(ymin)))
|
||||
t2 = invf(f(ymax) - 0.015*(f(ymax)-f(ymin)))
|
||||
|
||||
for xtick in xticks[1]
|
||||
tick_start, tick_stop = if sp[:framestyle] == :origin
|
||||
(0, t3)
|
||||
else
|
||||
xaxis[:mirror] ? (ymax, t2) : (ymin, t1)
|
||||
end
|
||||
push!(xtick_segs, (xtick, tick_start), (xtick, tick_stop)) # bottom tick
|
||||
push!(xaxis_segs, (xtick, ymin), (xtick, t1)) # bottom tick
|
||||
# sp[:draw_axes_border] && push!(xaxis_segs, (xtick, ymax), (xtick, t2)) # top tick
|
||||
xaxis[:grid] && push!(xgrid_segs, (xtick, t1), (xtick, t2)) # vertical grid
|
||||
end
|
||||
end
|
||||
|
||||
# yaxis
|
||||
sp[:framestyle] in (:grid, :origin, :zerolines) || push!(yaxis_segs, (xmin,ymin), (xmin,ymax)) # left spine / yaxis
|
||||
if sp[:framestyle] in (:origin, :zerolines)
|
||||
push!(yaxis_segs, (0.0, ymin), (0.0, ymax))
|
||||
# don't show the 0 tick label for the origin framestyle
|
||||
if sp[:framestyle] == :origin && length(yticks) > 1
|
||||
showticks = yticks[1] .!= 0
|
||||
yticks = (yticks[1][showticks], yticks[2][showticks])
|
||||
end
|
||||
end
|
||||
sp[:framestyle] == :grid || push!(yaxis_segs, (xmin,ymin), (xmin,ymax)) # left spine / yaxis
|
||||
sp[:framestyle] in (:semi, :box) && push!(yborder_segs, (xmax,ymin), (xmax,ymax)) # right spine
|
||||
if !(yaxis[:ticks] in (nothing, false))
|
||||
f = scalefunc(xaxis[:scale])
|
||||
invf = invscalefunc(xaxis[:scale])
|
||||
ticks_in = yaxis[:tick_direction] == :out ? -1 : 1
|
||||
t1 = invf(f(xmin) + 0.015 * (f(xmax) - f(xmin)) * ticks_in)
|
||||
t2 = invf(f(xmax) - 0.015 * (f(xmax) - f(xmin)) * ticks_in)
|
||||
t3 = invf(f(0) + 0.015 * (f(xmax) - f(xmin)) * ticks_in)
|
||||
t1 = invf(f(xmin) + 0.015*(f(xmax)-f(xmin)))
|
||||
t2 = invf(f(xmax) - 0.015*(f(xmax)-f(xmin)))
|
||||
|
||||
for ytick in yticks[1]
|
||||
tick_start, tick_stop = if sp[:framestyle] == :origin
|
||||
(0, t3)
|
||||
else
|
||||
yaxis[:mirror] ? (xmax, t2) : (xmin, t1)
|
||||
end
|
||||
push!(ytick_segs, (tick_start, ytick), (tick_stop, ytick)) # left tick
|
||||
push!(yaxis_segs, (xmin, ytick), (t1, ytick)) # left tick
|
||||
# sp[:draw_axes_border] && push!(yaxis_segs, (xmax, ytick), (t2, ytick)) # right tick
|
||||
yaxis[:grid] && push!(ygrid_segs, (t1, ytick), (t2, ytick)) # horizontal grid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
xticks, yticks, xaxis_segs, yaxis_segs, xtick_segs, ytick_segs, xgrid_segs, ygrid_segs, xborder_segs, yborder_segs
|
||||
xticks, yticks, xaxis_segs, yaxis_segs, xgrid_segs, ygrid_segs, xborder_segs, yborder_segs
|
||||
end
|
||||
|
||||
@@ -41,7 +41,6 @@ const _glvisualize_attr = merge_with_base_supported([
|
||||
:dpi,
|
||||
:hover,
|
||||
:framestyle,
|
||||
:tick_direction,
|
||||
])
|
||||
const _glvisualize_seriestype = [
|
||||
:path, :shape,
|
||||
@@ -605,7 +604,7 @@ end
|
||||
pointsize(font) = font.pointsize * 2
|
||||
|
||||
function draw_ticks(
|
||||
axis, ticks, isx, isorigin, lims, m, text = "",
|
||||
axis, ticks, isx, lims, m, text = "",
|
||||
positions = Point2f0[], offsets=Vec2f0[]
|
||||
)
|
||||
sz = pointsize(axis[:tickfont])
|
||||
@@ -623,11 +622,7 @@ function draw_ticks(
|
||||
for (cv, dv) in zip(ticks...)
|
||||
|
||||
x, y = cv, lims[1]
|
||||
xy = if isorigin
|
||||
isx ? (x, 0) : (0, x)
|
||||
else
|
||||
isx ? (x, y) : (y, x)
|
||||
end
|
||||
xy = isx ? (x, y) : (y, x)
|
||||
_pos = m * GeometryTypes.Vec4f0(xy[1], xy[2], 0, 1)
|
||||
startpos = Point2f0(_pos[1], _pos[2]) - axis_gap
|
||||
str = string(dv)
|
||||
@@ -683,7 +678,7 @@ function text_model(font, pivot)
|
||||
end
|
||||
end
|
||||
function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, area)
|
||||
xticks, yticks, xspine_segs, yspine_segs, xtick_segs, ytick_segs, xgrid_segs, ygrid_segs, xborder_segs, yborder_segs = Plots.axis_drawing_info(sp)
|
||||
xticks, yticks, xspine_segs, yspine_segs, xgrid_segs, ygrid_segs, xborder_segs, yborder_segs = Plots.axis_drawing_info(sp)
|
||||
xaxis = sp[:xaxis]; yaxis = sp[:yaxis]
|
||||
|
||||
xgc = Colors.color(Plots.gl_color(xaxis[:foreground_color_grid]))
|
||||
@@ -708,25 +703,6 @@ function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, are
|
||||
spine = draw_grid_lines(sp, yspine_segs, 1f0, :solid, model, RGBA(yac, 1.0f0))
|
||||
push!(axis_vis, spine)
|
||||
end
|
||||
if sp[:framestyle] in (:zerolines, :grid)
|
||||
if alpha(xaxis[:foreground_color_grid]) > 0
|
||||
spine = draw_grid_lines(sp, xtick_segs, 1f0, :solid, model, RGBA(xgc, xaxis[:gridalpha]))
|
||||
push!(axis_vis, spine)
|
||||
end
|
||||
if alpha(yaxis[:foreground_color_grid]) > 0
|
||||
spine = draw_grid_lines(sp, ytick_segs, 1f0, :solid, model, RGBA(ygc, yaxis[:gridalpha]))
|
||||
push!(axis_vis, spine)
|
||||
end
|
||||
else
|
||||
if alpha(xaxis[:foreground_color_axis]) > 0
|
||||
spine = draw_grid_lines(sp, xtick_segs, 1f0, :solid, model, RGBA(xac, 1.0f0))
|
||||
push!(axis_vis, spine)
|
||||
end
|
||||
if alpha(yaxis[:foreground_color_axis]) > 0
|
||||
spine = draw_grid_lines(sp, ytick_segs, 1f0, :solid, model, RGBA(yac, 1.0f0))
|
||||
push!(axis_vis, spine)
|
||||
end
|
||||
end
|
||||
fcolor = Plots.gl_color(xaxis[:foreground_color_axis])
|
||||
|
||||
xlim = Plots.axis_limits(xaxis)
|
||||
@@ -735,10 +711,10 @@ function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, are
|
||||
if !(xaxis[:ticks] in (nothing, false, :none)) && !(sp[:framestyle] == :none)
|
||||
ticklabels = map(model) do m
|
||||
mirror = xaxis[:mirror]
|
||||
t, positions, offsets = draw_ticks(xaxis, xticks, true, sp[:framestyle] == :origin, ylim, m)
|
||||
t, positions, offsets = draw_ticks(xaxis, xticks, true, ylim, m)
|
||||
mirror = xaxis[:mirror]
|
||||
t, positions, offsets = draw_ticks(
|
||||
yaxis, yticks, false, sp[:framestyle] == :origin, xlim, m,
|
||||
yaxis, yticks, false, xlim, m,
|
||||
t, positions, offsets
|
||||
)
|
||||
end
|
||||
|
||||
+65
-106
@@ -22,7 +22,7 @@ const _gr_attr = merge_with_base_supported([
|
||||
:tickfont, :guidefont, :legendfont,
|
||||
:grid, :gridalpha, :gridstyle, :gridlinewidth,
|
||||
:legend, :legendtitle, :colorbar,
|
||||
:fill_z, :line_z, :marker_z, :levels,
|
||||
:marker_z, :levels,
|
||||
:ribbon, :quiver,
|
||||
:orientation,
|
||||
:overwrite_figure,
|
||||
@@ -33,7 +33,6 @@ const _gr_attr = merge_with_base_supported([
|
||||
:bar_width,
|
||||
:arrow,
|
||||
:framestyle,
|
||||
:tick_direction,
|
||||
])
|
||||
const _gr_seriestype = [
|
||||
:path, :scatter,
|
||||
@@ -265,18 +264,17 @@ function gr_fill_viewport(vp::AVec{Float64}, c)
|
||||
end
|
||||
|
||||
|
||||
normalize_zvals(args...) = nothing
|
||||
function normalize_zvals(zv::AVec, clims::NTuple{2, <:Real})
|
||||
normalize_zvals(zv::Void) = zv
|
||||
function normalize_zvals(zv::AVec)
|
||||
vmin, vmax = ignorenan_extrema(zv)
|
||||
isfinite(clims[1]) && (vmin = clims[1])
|
||||
isfinite(clims[2]) && (vmax = clims[2])
|
||||
if vmin == vmax
|
||||
zeros(length(zv))
|
||||
else
|
||||
clamp.((zv - vmin) ./ (vmax - vmin), 0, 1)
|
||||
(zv - vmin) ./ (vmax - vmin)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
gr_alpha(α::Void) = 1
|
||||
gr_alpha(α::Real) = α
|
||||
|
||||
@@ -337,14 +335,14 @@ function gr_draw_markers(series::Series, x, y, msize, mz)
|
||||
end
|
||||
end
|
||||
|
||||
function gr_draw_markers(series::Series, x, y, clims)
|
||||
function gr_draw_markers(series::Series, x, y)
|
||||
isempty(x) && return
|
||||
mz = normalize_zvals(series[:marker_z], clims)
|
||||
mz = normalize_zvals(series[:marker_z])
|
||||
GR.setfillintstyle(GR.INTSTYLE_SOLID)
|
||||
gr_draw_markers(series, x, y, series[:markersize], mz)
|
||||
if hascolorbar(series[:subplot])
|
||||
if mz != nothing
|
||||
GR.setscale(0)
|
||||
gr_colorbar(series[:subplot], clims)
|
||||
gr_colorbar(series[:subplot])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -448,21 +446,11 @@ end
|
||||
|
||||
# add the colorbar
|
||||
function gr_colorbar(sp::Subplot)
|
||||
gr_set_viewport_cmap(sp)
|
||||
GR.colorbar()
|
||||
gr_set_viewport_plotarea()
|
||||
end
|
||||
|
||||
function gr_colorbar(sp::Subplot, clims)
|
||||
xmin, xmax = gr_xy_axislims(sp)[1:2]
|
||||
gr_set_viewport_cmap(sp)
|
||||
l = zeros(Int32, 1, 256)
|
||||
l[1,:] = Int[round(Int, _i) for _i in linspace(1000, 1255, 256)]
|
||||
GR.setwindow(xmin, xmax, clims[1], clims[2])
|
||||
GR.cellarray(xmin, xmax, clims[2], clims[1], 1, length(l), l)
|
||||
ztick = 0.5 * GR.tick(clims[1], clims[2])
|
||||
GR.axes(0, ztick, xmax, clims[1], 0, 1, 0.005)
|
||||
gr_set_viewport_plotarea()
|
||||
if sp[:colorbar] != :none
|
||||
gr_set_viewport_cmap(sp)
|
||||
GR.colorbar()
|
||||
gr_set_viewport_plotarea()
|
||||
end
|
||||
end
|
||||
|
||||
gr_view_xcenter() = 0.5 * (viewport_plotarea[1] + viewport_plotarea[2])
|
||||
@@ -592,10 +580,8 @@ function gr_get_ticks_size(ticks, i)
|
||||
end
|
||||
|
||||
function _update_min_padding!(sp::Subplot{GRBackend})
|
||||
if !haskey(ENV, "GKSwstype")
|
||||
if isijulia() || (isdefined(Main, :Juno) && Juno.isactive())
|
||||
ENV["GKSwstype"] = "svg"
|
||||
end
|
||||
if !haskey(ENV, "GKSwstype") && isijulia()
|
||||
ENV["GKSwstype"] = "svg"
|
||||
end
|
||||
# Add margin given by the user
|
||||
leftpad = 2mm + sp[:left_margin]
|
||||
@@ -674,11 +660,14 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
||||
# reduced from before... set some flags based on the series in this subplot
|
||||
# TODO: can these be generic flags?
|
||||
outside_ticks = false
|
||||
cmap = hascolorbar(sp)
|
||||
cmap = false
|
||||
draw_axes = sp[:framestyle] != :none
|
||||
# axes_2d = true
|
||||
for series in series_list(sp)
|
||||
st = series[:seriestype]
|
||||
if st in (:contour, :surface, :heatmap) || series[:marker_z] != nothing
|
||||
cmap = true
|
||||
end
|
||||
if st == :pie
|
||||
draw_axes = false
|
||||
end
|
||||
@@ -692,7 +681,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
||||
end
|
||||
end
|
||||
|
||||
if cmap
|
||||
if cmap && sp[:colorbar] != :none
|
||||
# note: add extra midpadding on the right for the colorbar
|
||||
viewport_plotarea[2] -= 0.1
|
||||
end
|
||||
@@ -750,7 +739,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
||||
isfinite(clims[1]) && (zmin = clims[1])
|
||||
isfinite(clims[2]) && (zmax = clims[2])
|
||||
end
|
||||
GR.setspace(zmin, zmax, 35, 60)
|
||||
GR.setspace(zmin, zmax, 40, 70)
|
||||
xtick = GR.tick(xmin, xmax) / 2
|
||||
ytick = GR.tick(ymin, ymax) / 2
|
||||
ztick = GR.tick(zmin, zmax) / 2
|
||||
@@ -774,7 +763,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
||||
GR.setwindow(xmin, xmax, ymin, ymax)
|
||||
end
|
||||
|
||||
xticks, yticks, xspine_segs, yspine_segs, xtick_segs, ytick_segs, xgrid_segs, ygrid_segs, xborder_segs, yborder_segs = axis_drawing_info(sp)
|
||||
xticks, yticks, xspine_segs, yspine_segs, xgrid_segs, ygrid_segs, xborder_segs, yborder_segs = axis_drawing_info(sp)
|
||||
# @show xticks yticks #spine_segs grid_segs
|
||||
|
||||
# draw the grid lines
|
||||
@@ -801,34 +790,15 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
||||
gr_polyline(coords(yspine_segs)...)
|
||||
GR.setclip(1)
|
||||
|
||||
# axis ticks
|
||||
if sp[:framestyle] in (:zerolines, :grid)
|
||||
gr_set_line(1, :solid, xaxis[:foreground_color_grid])
|
||||
GR.settransparency(xaxis[:gridalpha])
|
||||
else
|
||||
gr_set_line(1, :solid, xaxis[:foreground_color_axis])
|
||||
end
|
||||
GR.setclip(0)
|
||||
gr_polyline(coords(xtick_segs)...)
|
||||
if sp[:framestyle] in (:zerolines, :grid)
|
||||
gr_set_line(1, :solid, yaxis[:foreground_color_grid])
|
||||
GR.settransparency(yaxis[:gridalpha])
|
||||
else
|
||||
gr_set_line(1, :solid, yaxis[:foreground_color_axis])
|
||||
end
|
||||
GR.setclip(0)
|
||||
gr_polyline(coords(ytick_segs)...)
|
||||
GR.setclip(1)
|
||||
|
||||
# tick marks
|
||||
if !(xticks in (:none, nothing, false))
|
||||
# x labels
|
||||
flip, mirror = gr_set_xticks_font(sp)
|
||||
for (cv, dv) in zip(xticks...)
|
||||
# use xor ($) to get the right y coords
|
||||
xi, yi = GR.wctondc(cv, sp[:framestyle] == :origin ? 0 : xor(flip, mirror) ? ymax : ymin)
|
||||
xi, yi = GR.wctondc(cv, xor(flip, mirror) ? ymax : ymin)
|
||||
# @show cv dv ymin xi yi flip mirror (flip $ mirror)
|
||||
gr_text(xi, yi + (mirror ? 1 : -1) * 5e-3 * (xaxis[:tick_direction] == :out ? 1.5 : 1.0), string(dv))
|
||||
gr_text(xi, yi + (mirror ? 1 : -1) * 5e-3, string(dv))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -837,9 +807,9 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
||||
flip, mirror = gr_set_yticks_font(sp)
|
||||
for (cv, dv) in zip(yticks...)
|
||||
# use xor ($) to get the right y coords
|
||||
xi, yi = GR.wctondc(sp[:framestyle] == :origin ? 0 : xor(flip, mirror) ? xmax : xmin, cv)
|
||||
xi, yi = GR.wctondc(xor(flip, mirror) ? xmax : xmin, cv)
|
||||
# @show cv dv xmin xi yi
|
||||
gr_text(xi + (mirror ? 1 : -1) * 1e-2 * (yaxis[:tick_direction] == :out ? 1.5 : 1.0), yi, string(dv))
|
||||
gr_text(xi + (mirror ? 1 : -1) * 1e-2, yi, string(dv))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -886,9 +856,6 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
||||
# this needs to be here to point the colormap to the right indices
|
||||
GR.setcolormap(1000 + GR.COLORMAP_COOLWARM)
|
||||
|
||||
# calculate the colorbar limits once for a subplot
|
||||
clims = get_clims(sp)
|
||||
|
||||
for (idx, series) in enumerate(series_list(sp))
|
||||
st = series[:seriestype]
|
||||
|
||||
@@ -897,10 +864,6 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
||||
gr_set_gradient(series[:fillcolor]) #, series[:fillalpha])
|
||||
elseif series[:marker_z] != nothing
|
||||
series[:markercolor] = gr_set_gradient(series[:markercolor])
|
||||
elseif series[:line_z] != nothing
|
||||
series[:linecolor] = gr_set_gradient(series[:linecolor])
|
||||
elseif series[:fill_z] != nothing
|
||||
series[:fillcolor] = gr_set_gradient(series[:fillcolor])
|
||||
end
|
||||
|
||||
GR.savestate()
|
||||
@@ -939,29 +902,22 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
||||
if frng != nothing
|
||||
GR.setfillintstyle(GR.INTSTYLE_SOLID)
|
||||
fr_from, fr_to = (is_2tuple(frng) ? frng : (y, frng))
|
||||
for i in 1:length(x) - 1
|
||||
gr_set_fillcolor(get_fillcolor(sp, series, i))
|
||||
xseg = _cycle(x, [i, i+1, i+1, i])
|
||||
yseg = [_cycle(fr_from, [i, i+1]); _cycle(fr_to, [i+1, i])]
|
||||
series[:fillalpha] != nothing && GR.settransparency(series[:fillalpha])
|
||||
GR.fillarea(xseg, yseg)
|
||||
for (i,rng) in enumerate(iter_segments(series[:x], series[:y]))
|
||||
if length(rng) > 1
|
||||
gr_set_fillcolor(_cycle(series[:fillcolor], i))
|
||||
fx = _cycle(x, vcat(rng, reverse(rng)))
|
||||
fy = vcat(_cycle(fr_from,rng), _cycle(fr_to,reverse(rng)))
|
||||
# @show i rng fx fy
|
||||
GR.fillarea(fx, fy)
|
||||
end
|
||||
end
|
||||
gr_set_line(1, :solid, yaxis[:foreground_color_axis])
|
||||
GR.settransparency(1)
|
||||
cmap && gr_colorbar(sp, clims)
|
||||
end
|
||||
|
||||
# draw the line(s)
|
||||
if st == :path
|
||||
for i in 1:length(x) - 1
|
||||
xseg = x[i:(i + 1)]
|
||||
yseg = y[i:(i + 1)]
|
||||
gr_set_line(series[:linewidth], series[:linestyle], get_linecolor(sp, series, i)) #, series[:linealpha])
|
||||
arrowside = (i == length(y) - 1) && isa(series[:arrow], Arrow) ? series[:arrow].side : :none
|
||||
gr_polyline(xseg, yseg; arrowside = arrowside)
|
||||
end
|
||||
gr_set_line(1, :solid, yaxis[:foreground_color_axis])
|
||||
cmap && gr_colorbar(sp, clims)
|
||||
gr_set_line(series[:linewidth], series[:linestyle], series[:linecolor]) #, series[:linealpha])
|
||||
arrowside = isa(series[:arrow], Arrow) ? series[:arrow].side : :none
|
||||
gr_polyline(x, y; arrowside = arrowside)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -970,11 +926,16 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
||||
zmin, zmax = extrema(series[:marker_z])
|
||||
GR.setspace(zmin, zmax, 0, 90)
|
||||
end
|
||||
gr_draw_markers(series, x, y, clims)
|
||||
gr_draw_markers(series, x, y)
|
||||
end
|
||||
|
||||
elseif st == :contour
|
||||
zmin, zmax = clims
|
||||
zmin, zmax = gr_lims(zaxis, false)
|
||||
clims = sp[:clims]
|
||||
if is_2tuple(clims)
|
||||
isfinite(clims[1]) && (zmin = clims[1])
|
||||
isfinite(clims[2]) && (zmax = clims[2])
|
||||
end
|
||||
GR.setspace(zmin, zmax, 0, 90)
|
||||
if typeof(series[:levels]) <: Array
|
||||
h = series[:levels]
|
||||
@@ -988,7 +949,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
||||
end
|
||||
|
||||
# create the colorbar of contour levels
|
||||
if cmap
|
||||
if sp[:colorbar] != :none
|
||||
gr_set_viewport_cmap(sp)
|
||||
l = round.(Int32, 1000 + (h - ignorenan_minimum(h)) / (ignorenan_maximum(h) - ignorenan_minimum(h)) * 255)
|
||||
GR.setwindow(xmin, xmax, zmin, zmax)
|
||||
@@ -1013,7 +974,12 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
||||
|
||||
elseif st == :heatmap
|
||||
xmin, xmax, ymin, ymax = xy_lims
|
||||
zmin, zmax = clims
|
||||
zmin, zmax = gr_lims(zaxis, true)
|
||||
clims = sp[:clims]
|
||||
if is_2tuple(clims)
|
||||
isfinite(clims[1]) && (zmin = clims[1])
|
||||
isfinite(clims[2]) && (zmax = clims[2])
|
||||
end
|
||||
GR.setspace(zmin, zmax, 0, 90)
|
||||
grad = isa(series[:fillcolor], ColorGradient) ? series[:fillcolor] : cgrad()
|
||||
colors = [grad[clamp((zi-zmin) / (zmax-zmin), 0, 1)] for zi=z]
|
||||
@@ -1023,26 +989,21 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
||||
round(Int, red(c) * 255) ), colors)
|
||||
w, h = length(x), length(y)
|
||||
GR.drawimage(xmin, xmax, ymax, ymin, w, h, rgba)
|
||||
cmap && gr_colorbar(sp, clims)
|
||||
cmap && gr_colorbar(sp)
|
||||
|
||||
elseif st in (:path3d, :scatter3d)
|
||||
# draw path
|
||||
if st == :path3d
|
||||
for i in 1:length(x) - 1
|
||||
xseg = x[i:(i + 1)]
|
||||
yseg = y[i:(i + 1)]
|
||||
zseg = z[i:(i + 1)]
|
||||
gr_set_line(series[:linewidth], series[:linestyle], get_linecolor(sp, series, i)) #, series[:linealpha])
|
||||
GR.polyline3d(xseg, yseg, zseg)
|
||||
if length(x) > 1
|
||||
gr_set_line(series[:linewidth], series[:linestyle], series[:linecolor]) #, series[:linealpha])
|
||||
GR.polyline3d(x, y, z)
|
||||
end
|
||||
gr_set_line(1, :solid, yaxis[:foreground_color_axis])
|
||||
cmap && gr_colorbar(sp, clims)
|
||||
end
|
||||
|
||||
# draw markers
|
||||
if st == :scatter3d || series[:markershape] != :none
|
||||
x2, y2 = unzip(map(GR.wc3towc, x, y, z))
|
||||
gr_draw_markers(series, x2, y2, clims)
|
||||
gr_draw_markers(series, x2, y2)
|
||||
end
|
||||
|
||||
# TODO: replace with pie recipe
|
||||
@@ -1094,25 +1055,23 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
||||
GR.selntran(1)
|
||||
|
||||
elseif st == :shape
|
||||
for (i,rng) in enumerate(iter_segments(x, y))
|
||||
for (i,rng) in enumerate(iter_segments(series[:x], series[:y]))
|
||||
if length(rng) > 1
|
||||
# connect to the beginning
|
||||
rng = vcat(rng, rng[1])
|
||||
|
||||
# get the segments
|
||||
xseg, yseg = x[rng], y[rng]
|
||||
x, y = series[:x][rng], series[:y][rng]
|
||||
|
||||
# draw the interior
|
||||
gr_set_fill(get_fillcolor(sp, series, i))
|
||||
GR.fillarea(xseg, yseg)
|
||||
gr_set_fill(_cycle(series[:fillcolor], i))
|
||||
GR.fillarea(x, y)
|
||||
|
||||
# draw the shapes
|
||||
gr_set_line(series[:linewidth], :solid, get_linecolor(sp, series, i))
|
||||
GR.polyline(xseg, yseg)
|
||||
gr_set_line(series[:linewidth], :solid, _cycle(series[:linecolor], i))
|
||||
GR.polyline(x, y)
|
||||
end
|
||||
end
|
||||
gr_set_line(1, :solid, yaxis[:foreground_color_axis])
|
||||
cmap && gr_colorbar(sp, clims)
|
||||
|
||||
|
||||
elseif st == :image
|
||||
@@ -1188,10 +1147,10 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
||||
for series in series_list(sp)
|
||||
should_add_to_legend(series) || continue
|
||||
st = series[:seriestype]
|
||||
gr_set_line(series[:linewidth], series[:linestyle], get_linecolor(sp, series)) #, series[:linealpha])
|
||||
gr_set_line(series[:linewidth], series[:linestyle], series[:linecolor]) #, series[:linealpha])
|
||||
|
||||
if (st == :shape || series[:fillrange] != nothing) && series[:ribbon] == nothing
|
||||
gr_set_fill(get_fillcolor(sp, series)) #, series[:fillalpha])
|
||||
gr_set_fill(series[:fillcolor]) #, series[:fillalpha])
|
||||
l, r = xpos-0.07, xpos-0.01
|
||||
b, t = ypos-0.4dy, ypos+0.4dy
|
||||
x = [l, r, r, l, l]
|
||||
|
||||
@@ -31,7 +31,6 @@ const _pgfplots_attr = merge_with_base_supported([
|
||||
# :normalize, :weights, :contours,
|
||||
:aspect_ratio,
|
||||
# :match_dimensions,
|
||||
:tick_direction,
|
||||
])
|
||||
const _pgfplots_seriestype = [:path, :path3d, :scatter, :steppre, :stepmid, :steppost, :histogram2d, :ysticks, :xsticks, :contour, :shape]
|
||||
const _pgfplots_style = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
|
||||
@@ -280,11 +279,10 @@ function pgf_axis(sp::Subplot, letter)
|
||||
kw[Symbol(letter,:max)] = lims[2]
|
||||
end
|
||||
|
||||
if !(axis[:ticks] in (nothing, false, :none))
|
||||
if !(axis[:ticks] in (nothing, false, :none, :auto))
|
||||
ticks = get_ticks(axis)
|
||||
push!(style, string(letter, "tick = {", join(ticks[1],","), "}"))
|
||||
push!(style, string(letter, "ticklabels = {", join(ticks[2],","), "}"))
|
||||
push!(style, string(letter, "tick align = ", (axis[:tick_direction] == :out ? "outside" : "inside")))
|
||||
end
|
||||
|
||||
# return the style list and KW args
|
||||
|
||||
+9
-35
@@ -33,8 +33,6 @@ const _plotly_attr = merge_with_base_supported([
|
||||
:inset_subplots,
|
||||
:bar_width,
|
||||
:clims,
|
||||
:framestyle,
|
||||
:tick_direction,
|
||||
])
|
||||
|
||||
const _plotly_seriestype = [
|
||||
@@ -49,17 +47,6 @@ const _plotly_marker = [
|
||||
const _plotly_scale = [:identity, :log10]
|
||||
is_subplot_supported(::PlotlyBackend) = true
|
||||
# is_string_supported(::PlotlyBackend) = true
|
||||
const _plotly_framestyles = [:box, :axes, :zerolines, :grid, :none]
|
||||
const _plotly_framestyle_defaults = Dict(:semi => :box, :origin => :zerolines)
|
||||
function _plotly_framestyle(style::Symbol)
|
||||
if style in _plotly_framestyles
|
||||
return style
|
||||
else
|
||||
default_style = get(_plotly_framestyle_defaults, style, :axes)
|
||||
warn("Framestyle :$style is not supported by Plotly and PlotlyJS. :$default_style was cosen instead.")
|
||||
default_style
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------------------
|
||||
@@ -225,19 +212,13 @@ end
|
||||
|
||||
function plotly_axis(axis::Axis, sp::Subplot)
|
||||
letter = axis[:letter]
|
||||
framestyle = sp[:framestyle]
|
||||
ax = KW(
|
||||
:visible => framestyle != :none,
|
||||
:title => axis[:guide],
|
||||
:showgrid => axis[:grid],
|
||||
:gridcolor => rgba_string(plot_color(axis[:foreground_color_grid], axis[:gridalpha])),
|
||||
:gridwidth => axis[:gridlinewidth],
|
||||
:zeroline => framestyle == :zerolines,
|
||||
:zerolinecolor => rgba_string(axis[:foreground_color_axis]),
|
||||
:showline => framestyle in (:box, :axes),
|
||||
:linecolor => rgba_string(plot_color(axis[:foreground_color_axis])),
|
||||
:ticks => axis[:tick_direction] == :out ? "outside" : "inside",
|
||||
:mirror => framestyle == :box,
|
||||
:zeroline => false,
|
||||
:ticks => "inside",
|
||||
)
|
||||
|
||||
if letter in (:x,:y)
|
||||
@@ -251,7 +232,7 @@ function plotly_axis(axis::Axis, sp::Subplot)
|
||||
ax[:titlefont] = plotly_font(axis[:guidefont], axis[:foreground_color_guide])
|
||||
ax[:type] = plotly_scale(axis[:scale])
|
||||
ax[:tickfont] = plotly_font(axis[:tickfont], axis[:foreground_color_text])
|
||||
ax[:tickcolor] = framestyle in (:zerolines, :grid) ? rgba_string(invisible()) : rgb_string(axis[:foreground_color_axis])
|
||||
ax[:tickcolor] = rgba_string(axis[:foreground_color_axis])
|
||||
ax[:linecolor] = rgba_string(axis[:foreground_color_axis])
|
||||
|
||||
# lims
|
||||
@@ -318,9 +299,6 @@ function plotly_layout(plt::Plot)
|
||||
|
||||
d_out[:plot_bgcolor] = rgba_string(sp[:background_color_inside])
|
||||
|
||||
# set to supported framestyle
|
||||
sp[:framestyle] = _plotly_framestyle(sp[:framestyle])
|
||||
|
||||
# if any(is3d, seriesargs)
|
||||
if is3d(sp)
|
||||
d_out[:scene] = KW(
|
||||
@@ -576,18 +554,14 @@ function plotly_series(plt::Plot, series::Series)
|
||||
)
|
||||
|
||||
# gotta hack this (for now?) since plotly can't handle rgba values inside the gradient
|
||||
if series[:marker_z] == nothing
|
||||
d_out[:marker][:color] = rgba_string(series[:markercolor])
|
||||
d_out[:marker][:color] = if series[:marker_z] == nothing
|
||||
rgba_string(series[:markercolor])
|
||||
else
|
||||
# grad = ColorGradient(series[:markercolor], alpha=series[:markeralpha])
|
||||
# grad = as_gradient(series[:markercolor], series[:markeralpha])
|
||||
cmin, cmax = get_clims(sp)
|
||||
# zrange = zmax == zmin ? 1 : zmax - zmin # if all marker_z values are the same, plot all markers same color (avoids division by zero in next line)
|
||||
d_out[:marker][:color] = [clamp(zi, cmin, cmax) for zi in series[:marker_z]]
|
||||
d_out[:marker][:cmin] = cmin
|
||||
d_out[:marker][:cmax] = cmax
|
||||
d_out[:marker][:colorscale] = plotly_colorscale(series[:markercolor], series[:markeralpha])
|
||||
d_out[:marker][:showscale] = hascolorbar(sp)
|
||||
grad = as_gradient(series[:markercolor], series[:markeralpha])
|
||||
zmin, zmax = ignorenan_extrema(series[:marker_z])
|
||||
zrange = zmax == zmin ? 1 : zmax - zmin # if all marker_z values are the same, plot all markers same color (avoids division by zero in next line)
|
||||
[rgba_string(grad[(zi - zmin) / zrange]) for zi in series[:marker_z]]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
+93
-74
@@ -32,9 +32,7 @@ const _pyplot_attr = merge_with_base_supported([
|
||||
:inset_subplots,
|
||||
:dpi,
|
||||
:colorbar_title,
|
||||
:stride,
|
||||
:framestyle,
|
||||
:tick_direction,
|
||||
])
|
||||
const _pyplot_seriestype = [
|
||||
:path, :steppre, :steppost, :shape,
|
||||
@@ -445,16 +443,11 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
||||
xyargs = (st in _3dTypes ? (x,y,z) : (x,y))
|
||||
|
||||
# handle zcolor and get c/cmap
|
||||
needs_colorbar = hascolorbar(sp)
|
||||
extrakw = if needs_colorbar || is_2tuple(sp[:clims])
|
||||
vmin, vmax = get_clims(sp)
|
||||
KW(:vmin => vmin, :vmax => vmax)
|
||||
else
|
||||
KW()
|
||||
end
|
||||
extrakw = KW()
|
||||
|
||||
# holds references to any python object representing the matplotlib series
|
||||
handles = []
|
||||
needs_colorbar = false
|
||||
discrete_colorbar_values = nothing
|
||||
|
||||
|
||||
@@ -501,7 +494,11 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
||||
:linewidth => py_dpi_scale(plt, series[:linewidth]),
|
||||
:linestyle => py_linestyle(st, series[:linestyle])
|
||||
)
|
||||
if needs_colorbar
|
||||
clims = sp[:clims]
|
||||
if is_2tuple(clims)
|
||||
extrakw = KW()
|
||||
isfinite(clims[1]) && (extrakw[:vmin] = clims[1])
|
||||
isfinite(clims[2]) && (extrakw[:vmax] = clims[2])
|
||||
kw[:norm] = pycolors["Normalize"](; extrakw...)
|
||||
end
|
||||
lz = collect(series[:line_z])
|
||||
@@ -531,6 +528,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
||||
lc
|
||||
end
|
||||
push!(handles, handle)
|
||||
needs_colorbar = true
|
||||
end
|
||||
|
||||
a = series[:arrow]
|
||||
@@ -564,11 +562,18 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
||||
if series[:markershape] != :none && st in (:path, :scatter, :path3d,
|
||||
:scatter3d, :steppre, :steppost,
|
||||
:bar)
|
||||
extrakw = KW()
|
||||
if series[:marker_z] == nothing
|
||||
extrakw[:c] = py_color_fix(py_markercolor(series), x)
|
||||
else
|
||||
extrakw[:c] = convert(Vector{Float64}, series[:marker_z])
|
||||
extrakw[:cmap] = py_markercolormap(series)
|
||||
clims = sp[:clims]
|
||||
if is_2tuple(clims)
|
||||
isfinite(clims[1]) && (extrakw[:vmin] = clims[1])
|
||||
isfinite(clims[2]) && (extrakw[:vmax] = clims[2])
|
||||
end
|
||||
needs_colorbar = true
|
||||
end
|
||||
xyargs = if st == :bar && !isvertical(series)
|
||||
(y, x)
|
||||
@@ -618,6 +623,11 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
||||
end
|
||||
|
||||
if st == :hexbin
|
||||
clims = sp[:clims]
|
||||
if is_2tuple(clims)
|
||||
isfinite(clims[1]) && (extrakw[:vmin] = clims[1])
|
||||
isfinite(clims[2]) && (extrakw[:vmax] = clims[2])
|
||||
end
|
||||
handle = ax[:hexbin](x, y;
|
||||
label = series[:label],
|
||||
zorder = series[:series_plotindex],
|
||||
@@ -628,10 +638,18 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
||||
extrakw...
|
||||
)
|
||||
push!(handles, handle)
|
||||
needs_colorbar = true
|
||||
end
|
||||
|
||||
if st in (:contour, :contour3d)
|
||||
z = transpose_z(series, z.surf)
|
||||
needs_colorbar = true
|
||||
|
||||
clims = sp[:clims]
|
||||
if is_2tuple(clims)
|
||||
isfinite(clims[1]) && (extrakw[:vmin] = clims[1])
|
||||
isfinite(clims[2]) && (extrakw[:vmax] = clims[2])
|
||||
end
|
||||
|
||||
if st == :contour3d
|
||||
extrakw[:extend3d] = true
|
||||
@@ -669,6 +687,11 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
||||
end
|
||||
z = transpose_z(series, z)
|
||||
if st == :surface
|
||||
clims = sp[:clims]
|
||||
if is_2tuple(clims)
|
||||
isfinite(clims[1]) && (extrakw[:vmin] = clims[1])
|
||||
isfinite(clims[2]) && (extrakw[:vmax] = clims[2])
|
||||
end
|
||||
if series[:fill_z] != nothing
|
||||
# the surface colors are different than z-value
|
||||
extrakw[:facecolors] = py_shading(series[:fillcolor], transpose_z(series, series[:fill_z].surf))
|
||||
@@ -676,12 +699,13 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
||||
else
|
||||
extrakw[:cmap] = py_fillcolormap(series)
|
||||
end
|
||||
needs_colorbar = true
|
||||
end
|
||||
handle = ax[st == :surface ? :plot_surface : :plot_wireframe](x, y, z;
|
||||
label = series[:label],
|
||||
zorder = series[:series_plotindex],
|
||||
rstride = series[:stride][1],
|
||||
cstride = series[:stride][2],
|
||||
rstride = 1,
|
||||
cstride = 1,
|
||||
linewidth = py_dpi_scale(plt, series[:linewidth]),
|
||||
edgecolor = py_linecolor(series),
|
||||
extrakw...
|
||||
@@ -698,9 +722,14 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
||||
offset = (zdir == "y" ? ignorenan_maximum : ignorenan_minimum)(mat) # where to draw the contour plane
|
||||
)
|
||||
push!(handles, handle)
|
||||
needs_colorbar = true
|
||||
end
|
||||
end
|
||||
|
||||
# no colorbar if we are creating a surface LightSource
|
||||
if haskey(extrakw, :facecolors)
|
||||
needs_colorbar = false
|
||||
end
|
||||
|
||||
elseif typeof(z) <: AbstractVector
|
||||
# tri-surface plot (http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#tri-surface-plots)
|
||||
@@ -718,6 +747,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
||||
extrakw...
|
||||
)
|
||||
push!(handles, handle)
|
||||
needs_colorbar = true
|
||||
else
|
||||
error("Unsupported z type $(typeof(z)) for seriestype=$st")
|
||||
end
|
||||
@@ -757,6 +787,11 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
||||
discrete_colorbar_values = dvals
|
||||
end
|
||||
|
||||
clims = sp[:clims]
|
||||
zmin, zmax = ignorenan_extrema(z)
|
||||
extrakw[:vmin] = (is_2tuple(clims) && isfinite(clims[1])) ? clims[1] : zmin
|
||||
extrakw[:vmax] = (is_2tuple(clims) && isfinite(clims[2])) ? clims[2] : zmax
|
||||
|
||||
handle = ax[:pcolormesh](x, y, py_mask_nans(z);
|
||||
label = series[:label],
|
||||
zorder = series[:series_plotindex],
|
||||
@@ -765,6 +800,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
||||
extrakw...
|
||||
)
|
||||
push!(handles, handle)
|
||||
needs_colorbar = true
|
||||
end
|
||||
|
||||
if st == :shape
|
||||
@@ -807,6 +843,30 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
||||
# # smoothing
|
||||
# handleSmooth(plt, ax, series, series[:smooth])
|
||||
|
||||
# add the colorbar legend
|
||||
if needs_colorbar && sp[:colorbar] != :none
|
||||
# add keyword args for a discrete colorbar
|
||||
handle = handles[end]
|
||||
kw = KW()
|
||||
if discrete_colorbar_values != nothing
|
||||
locator, formatter = get_locator_and_formatter(discrete_colorbar_values)
|
||||
# kw[:values] = 1:length(discrete_colorbar_values)
|
||||
kw[:values] = sp[:zaxis][:continuous_values]
|
||||
kw[:ticks] = locator
|
||||
kw[:format] = formatter
|
||||
kw[:boundaries] = vcat(0, kw[:values] + 0.5)
|
||||
end
|
||||
|
||||
# create and store the colorbar object (handle) and the axis that it is drawn on.
|
||||
# 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()))
|
||||
cb = fig[:colorbar](handle; cax = cbax, kw...)
|
||||
cb[:set_label](sp[:colorbar_title])
|
||||
sp.attr[:cbar_handle] = cb
|
||||
sp.attr[:cbar_ax] = cbax
|
||||
end
|
||||
|
||||
# handle area filling
|
||||
fillrange = series[:fillrange]
|
||||
if fillrange != nothing && st != :contour
|
||||
@@ -904,22 +964,21 @@ function py_set_scale(ax, axis::Axis)
|
||||
elseif scale == :log10
|
||||
10
|
||||
end
|
||||
kw[Symbol(:linthresh,letter)] = NaNMath.min(1e-16, py_compute_axis_minval(axis))
|
||||
kw[Symbol(:linthresh,letter)] = NaNMath.max(1e-16, py_compute_axis_minval(axis))
|
||||
"symlog"
|
||||
end
|
||||
func(arg; kw...)
|
||||
end
|
||||
|
||||
|
||||
function py_set_axis_colors(sp, ax, a::Axis)
|
||||
function py_set_axis_colors(ax, a::Axis)
|
||||
for (loc, spine) in ax[:spines]
|
||||
spine[:set_color](py_color(a[:foreground_color_border]))
|
||||
end
|
||||
axissym = Symbol(a[:letter], :axis)
|
||||
if haskey(ax, axissym)
|
||||
tickcolor = sp[:framestyle] == :zerolines ? py_color(plot_color(a[:foreground_color_grid], a[:gridalpha])) : py_color(a[:foreground_color_axis])
|
||||
ax[:tick_params](axis=string(a[:letter]), which="both",
|
||||
colors=tickcolor,
|
||||
colors=py_color(a[:foreground_color_axis]),
|
||||
labelcolor=py_color(a[:foreground_color_text]))
|
||||
ax[axissym][:label][:set_color](py_color(a[:foreground_color_guide]))
|
||||
end
|
||||
@@ -981,58 +1040,6 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
|
||||
# ax[:set_title](sp[:title], loc = loc)
|
||||
end
|
||||
|
||||
# add the colorbar legend
|
||||
if hascolorbar(sp)
|
||||
# add keyword args for a discrete colorbar
|
||||
slist = series_list(sp)
|
||||
colorbar_series = slist[findfirst(hascolorbar.(slist))]
|
||||
handle = colorbar_series[:serieshandle][end]
|
||||
kw = KW()
|
||||
if !isempty(sp[:zaxis][:discrete_values]) && colorbar_series[:seriestype] == :heatmap
|
||||
locator, formatter = get_locator_and_formatter(sp[:zaxis][:discrete_values])
|
||||
# kw[:values] = 1:length(sp[:zaxis][:discrete_values])
|
||||
kw[:values] = sp[:zaxis][:continuous_values]
|
||||
kw[:ticks] = locator
|
||||
kw[:format] = formatter
|
||||
kw[:boundaries] = vcat(0, kw[:values] + 0.5)
|
||||
end
|
||||
|
||||
# create and store the colorbar object (handle) and the axis that it is drawn on.
|
||||
# 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()))
|
||||
cb = fig[:colorbar](handle; cax = cbax, kw...)
|
||||
cb[:set_label](sp[:colorbar_title])
|
||||
sp.attr[:cbar_handle] = cb
|
||||
sp.attr[:cbar_ax] = cbax
|
||||
end
|
||||
|
||||
# framestyle
|
||||
if !ispolar(sp) && !is3d(sp)
|
||||
if sp[:framestyle] == :semi
|
||||
intensity = 0.5
|
||||
ax[:spines]["right"][:set_alpha](intensity)
|
||||
ax[:spines]["top"][:set_alpha](intensity)
|
||||
ax[:spines]["right"][:set_linewidth](intensity)
|
||||
ax[:spines]["top"][:set_linewidth](intensity)
|
||||
elseif sp[:framestyle] in (:axes, :origin)
|
||||
ax[:spines]["right"][:set_visible](false)
|
||||
ax[:spines]["top"][:set_visible](false)
|
||||
if sp[:framestyle] == :origin
|
||||
ax[:spines]["bottom"][:set_position]("zero")
|
||||
ax[:spines]["left"][:set_position]("zero")
|
||||
end
|
||||
elseif sp[:framestyle] in (:grid, :none, :zerolines)
|
||||
for (loc, spine) in ax[:spines]
|
||||
spine[:set_visible](false)
|
||||
end
|
||||
if sp[:framestyle] == :zerolines
|
||||
ax[:axhline](y = 0, color = py_color(sp[:xaxis][:foreground_color_axis]), lw = 0.75)
|
||||
ax[:axvline](x = 0, color = py_color(sp[:yaxis][:foreground_color_axis]), lw = 0.75)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# axis attributes
|
||||
for letter in (:x, :y, :z)
|
||||
axissym = Symbol(letter, :axis)
|
||||
@@ -1048,12 +1055,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
|
||||
py_set_scale(ax, axis)
|
||||
py_set_lims(ax, axis)
|
||||
ticks = sp[:framestyle] == :none ? nothing : get_ticks(axis)
|
||||
# don't show the 0 tick label for the origin framestyle
|
||||
if sp[:framestyle] == :origin && length(ticks) > 1
|
||||
ticks[2][ticks[1] .== 0] = ""
|
||||
end
|
||||
py_set_ticks(ax, ticks, letter)
|
||||
pyaxis[:set_tick_params](direction = axis[:tick_direction] == :out ? "out" : "in")
|
||||
ax[Symbol("set_", letter, "label")](axis[:guide])
|
||||
if get(axis.d, :flip, false)
|
||||
ax[Symbol("invert_", letter, "axis")]()
|
||||
@@ -1074,7 +1076,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
|
||||
alpha = axis[:gridalpha])
|
||||
ax[:set_axisbelow](true)
|
||||
end
|
||||
py_set_axis_colors(sp, ax, axis)
|
||||
py_set_axis_colors(ax, axis)
|
||||
end
|
||||
|
||||
# aspect ratio
|
||||
@@ -1089,6 +1091,23 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
|
||||
# this sets the bg color inside the grid
|
||||
ax[set_facecolor_sym](py_color(sp[:background_color_inside]))
|
||||
|
||||
# framestyle
|
||||
if !ispolar(sp) && !is3d(sp)
|
||||
if sp[:framestyle] == :semi
|
||||
intensity = 0.5
|
||||
ax[:spines]["right"][:set_alpha](intensity)
|
||||
ax[:spines]["top"][:set_alpha](intensity)
|
||||
ax[:spines]["right"][:set_linewidth](intensity)
|
||||
ax[:spines]["top"][:set_linewidth](intensity)
|
||||
elseif sp[:framestyle] == :axes
|
||||
ax[:spines]["right"][:set_visible](false)
|
||||
ax[:spines]["top"][:set_visible](false)
|
||||
elseif sp[:framestyle] in (:grid, :none)
|
||||
for (loc, spine) in ax[:spines]
|
||||
spine[:set_visible](false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
py_drawfig(fig)
|
||||
end
|
||||
|
||||
+1
-1
@@ -89,7 +89,7 @@ end
|
||||
"create a shape by picking points around the unit circle. `n` is the number of point/sides, `offset` is the starting angle"
|
||||
function makeshape(n; offset = -0.5, radius = 1.0)
|
||||
z = offset * π
|
||||
Shape(partialcircle(z, z + 2π, n+1, radius))
|
||||
Shape(partialcircle(z, z + 2π, n+1., radius))
|
||||
end
|
||||
|
||||
|
||||
|
||||
+1
-2
@@ -288,10 +288,9 @@ PlotExample("Heatmap, categorical axes, and aspect_ratio",
|
||||
PlotExample("Layouts, margins, label rotation, title location",
|
||||
"",
|
||||
[:(begin
|
||||
using Plots.PlotMeasures # for Measures, e.g. mm and px
|
||||
plot(rand(100,6),layout=@layout([a b; c]),title=["A" "B" "C"],
|
||||
title_location=:left, left_margin=[20mm 0mm],
|
||||
bottom_margin=10px, xrotation=60)
|
||||
bottom_margin=50px, xrotation=60)
|
||||
end)]
|
||||
),
|
||||
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ ps(fn::AbstractString) = ps(current(), fn)
|
||||
function eps(plt::Plot, fn::AbstractString)
|
||||
fn = addExtension(fn, "eps")
|
||||
io = open(fn, "w")
|
||||
show(io, MIME("image/eps"), plt)
|
||||
writemime(io, MIME("image/eps"), plt)
|
||||
close(io)
|
||||
end
|
||||
eps(fn::AbstractString) = eps(current(), fn)
|
||||
|
||||
@@ -364,11 +364,6 @@ function _expand_subplot_extrema(sp::Subplot, d::KW, st::Symbol)
|
||||
elseif !(st in (:pie, :histogram, :bins2d, :histogram2d))
|
||||
expand_extrema!(sp, d)
|
||||
end
|
||||
# expand for zerolines (axes through origin)
|
||||
if sp[:framestyle] in (:origin, :zerolines)
|
||||
expand_extrema!(sp[:xaxis], 0.0)
|
||||
expand_extrema!(sp[:yaxis], 0.0)
|
||||
end
|
||||
end
|
||||
|
||||
function _add_the_series(plt, sp, d)
|
||||
|
||||
+1
-1
@@ -84,7 +84,7 @@ function plot(plt1::Plot, plts_tail::Plot...; kw...)
|
||||
# TODO: replace this with proper processing from a merged user_attr KW
|
||||
# update plot args, first with existing plots, then override with d
|
||||
for p in plts
|
||||
_update_plot_args(plt, copy(p.attr))
|
||||
_update_plot_args(plt, p.attr)
|
||||
plt.n += p.n
|
||||
end
|
||||
_update_plot_args(plt, d)
|
||||
|
||||
+51
-58
@@ -79,7 +79,7 @@ function hvline_limits(axis::Axis)
|
||||
end
|
||||
|
||||
@recipe function f(::Type{Val{:hline}}, x, y, z)
|
||||
xmin, xmax = hvline_limits(plotattributes[:subplot][:xaxis])
|
||||
xmin, xmax = hvline_limits(d[:subplot][:xaxis])
|
||||
n = length(y)
|
||||
newx = repmat(Float64[xmin, xmax, NaN], n)
|
||||
newy = vec(Float64[yi for i=1:3,yi=y])
|
||||
@@ -91,7 +91,7 @@ end
|
||||
@deps hline path
|
||||
|
||||
@recipe function f(::Type{Val{:vline}}, x, y, z)
|
||||
ymin, ymax = hvline_limits(plotattributes[:subplot][:yaxis])
|
||||
ymin, ymax = hvline_limits(d[:subplot][:yaxis])
|
||||
n = length(y)
|
||||
newx = vec(Float64[yi for i=1:3,yi=y])
|
||||
newy = repmat(Float64[ymin, ymax, NaN], n)
|
||||
@@ -123,11 +123,11 @@ end
|
||||
|
||||
# create a path from steps
|
||||
@recipe function f(::Type{Val{:steppre}}, x, y, z)
|
||||
plotattributes[:x], plotattributes[:y] = make_steps(x, y, :steppre)
|
||||
d[:x], d[:y] = make_steps(x, y, :steppre)
|
||||
seriestype := :path
|
||||
|
||||
# create a secondary series for the markers
|
||||
if plotattributes[:markershape] != :none
|
||||
if d[:markershape] != :none
|
||||
@series begin
|
||||
seriestype := :scatter
|
||||
x := x
|
||||
@@ -144,11 +144,11 @@ end
|
||||
|
||||
# create a path from steps
|
||||
@recipe function f(::Type{Val{:steppost}}, x, y, z)
|
||||
plotattributes[:x], plotattributes[:y] = make_steps(x, y, :steppost)
|
||||
d[:x], d[:y] = make_steps(x, y, :steppost)
|
||||
seriestype := :path
|
||||
|
||||
# create a secondary series for the markers
|
||||
if plotattributes[:markershape] != :none
|
||||
if d[:markershape] != :none
|
||||
@series begin
|
||||
seriestype := :scatter
|
||||
x := x
|
||||
@@ -170,9 +170,9 @@ end
|
||||
# create vertical line segments from fill
|
||||
@recipe function f(::Type{Val{:sticks}}, x, y, z)
|
||||
n = length(x)
|
||||
fr = plotattributes[:fillrange]
|
||||
fr = d[:fillrange]
|
||||
if fr == nothing
|
||||
yaxis = plotattributes[:subplot][:yaxis]
|
||||
yaxis = d[:subplot][:yaxis]
|
||||
fr = if yaxis[:scale] == :identity
|
||||
0.0
|
||||
else
|
||||
@@ -191,7 +191,7 @@ end
|
||||
seriestype := :path
|
||||
|
||||
# create a secondary series for the markers
|
||||
if plotattributes[:markershape] != :none
|
||||
if d[:markershape] != :none
|
||||
@series begin
|
||||
seriestype := :scatter
|
||||
x := x
|
||||
@@ -224,7 +224,7 @@ end
|
||||
@recipe function f(::Type{Val{:curves}}, x, y, z; npoints = 30)
|
||||
args = z != nothing ? (x,y,z) : (x,y)
|
||||
newx, newy = zeros(0), zeros(0)
|
||||
fr = plotattributes[:fillrange]
|
||||
fr = d[:fillrange]
|
||||
newfr = fr != nothing ? zeros(0) : nothing
|
||||
newz = z != nothing ? zeros(0) : nothing
|
||||
# lz = d[:line_z]
|
||||
@@ -274,9 +274,9 @@ end
|
||||
|
||||
# create a bar plot as a filled step function
|
||||
@recipe function f(::Type{Val{:bar}}, x, y, z)
|
||||
procx, procy, xscale, yscale, baseline = _preprocess_barlike(plotattributes, x, y)
|
||||
procx, procy, xscale, yscale, baseline = _preprocess_barlike(d, x, y)
|
||||
nx, ny = length(procx), length(procy)
|
||||
axis = plotattributes[:subplot][isvertical(plotattributes) ? :xaxis : :yaxis]
|
||||
axis = d[:subplot][isvertical(d) ? :xaxis : :yaxis]
|
||||
cv = [discrete_value!(axis, xi)[1] for xi=procx]
|
||||
procx = if nx == ny
|
||||
cv
|
||||
@@ -287,15 +287,15 @@ end
|
||||
end
|
||||
|
||||
# compute half-width of bars
|
||||
bw = plotattributes[:bar_width]
|
||||
bw = d[:bar_width]
|
||||
hw = if bw == nothing
|
||||
0.5*_bar_width*ignorenan_minimum(filter(x->x>0, diff(procx)))
|
||||
0.5ignorenan_mean(diff(procx))
|
||||
else
|
||||
Float64[0.5_cycle(bw,i) for i=1:length(procx)]
|
||||
end
|
||||
|
||||
# make fillto a vector... default fills to 0
|
||||
fillto = plotattributes[:fillrange]
|
||||
fillto = d[:fillrange]
|
||||
if fillto == nothing
|
||||
fillto = 0
|
||||
end
|
||||
@@ -320,7 +320,7 @@ end
|
||||
expand_extrema!(axis, widen(ignorenan_extrema(xseg.pts)...))
|
||||
|
||||
# switch back
|
||||
if !isvertical(plotattributes)
|
||||
if !isvertical(d)
|
||||
xseg, yseg = yseg, xseg
|
||||
end
|
||||
|
||||
@@ -389,8 +389,8 @@ end
|
||||
|
||||
|
||||
@recipe function f(::Type{Val{:barbins}}, x, y, z)
|
||||
edge, weights, xscale, yscale, baseline = _preprocess_binlike(plotattributes, x, y)
|
||||
if (plotattributes[:bar_width] == nothing)
|
||||
edge, weights, xscale, yscale, baseline = _preprocess_binlike(d, x, y)
|
||||
if (d[:bar_width] == nothing)
|
||||
bar_width := diff(edge)
|
||||
end
|
||||
x := _bin_centers(edge)
|
||||
@@ -402,7 +402,7 @@ end
|
||||
|
||||
|
||||
@recipe function f(::Type{Val{:scatterbins}}, x, y, z)
|
||||
edge, weights, xscale, yscale, baseline = _preprocess_binlike(plotattributes, x, y)
|
||||
edge, weights, xscale, yscale, baseline = _preprocess_binlike(d, x, y)
|
||||
xerror := diff(edge)/2
|
||||
x := _bin_centers(edge)
|
||||
y := weights
|
||||
@@ -465,17 +465,17 @@ end
|
||||
|
||||
|
||||
@recipe function f(::Type{Val{:stepbins}}, x, y, z)
|
||||
axis = plotattributes[:subplot][Plots.isvertical(plotattributes) ? :xaxis : :yaxis]
|
||||
axis = d[:subplot][Plots.isvertical(d) ? :xaxis : :yaxis]
|
||||
|
||||
edge, weights, xscale, yscale, baseline = _preprocess_binlike(plotattributes, x, y)
|
||||
edge, weights, xscale, yscale, baseline = _preprocess_binlike(d, x, y)
|
||||
|
||||
xpts, ypts = _stepbins_path(edge, weights, baseline, xscale, yscale)
|
||||
if !isvertical(plotattributes)
|
||||
if !isvertical(d)
|
||||
xpts, ypts = ypts, xpts
|
||||
end
|
||||
|
||||
# create a secondary series for the markers
|
||||
if plotattributes[:markershape] != :none
|
||||
if d[:markershape] != :none
|
||||
@series begin
|
||||
seriestype := :scatter
|
||||
x := _bin_centers(edge)
|
||||
@@ -497,40 +497,33 @@ end
|
||||
end
|
||||
Plots.@deps stepbins path
|
||||
|
||||
wand_edges(x...) = (warn("Load the StatPlots package in order to use :wand bins. Defaulting to :auto", once = true); :auto)
|
||||
|
||||
function _auto_binning_nbins{N}(vs::NTuple{N,AbstractVector}, dim::Integer; mode::Symbol = :auto)
|
||||
_cl(x) = ceil(Int, NaNMath.max(x, one(x)))
|
||||
_iqr(v) = (q = quantile(v, 0.75) - quantile(v, 0.25); q > 0 ? q : oftype(q, 1))
|
||||
_iqr(v) = quantile(v, 0.75) - quantile(v, 0.25)
|
||||
_span(v) = ignorenan_maximum(v) - ignorenan_minimum(v)
|
||||
|
||||
n_samples = length(linearindices(first(vs)))
|
||||
|
||||
# The nd estimator is the key to most automatic binning methods, and is modified for twodimensional histograms to include correlation
|
||||
nd = n_samples^(1/(2+N))
|
||||
nd = N == 2 ? nd / (1-cor(first(vs), last(vs))^2)^(3//8) : nd # the >2-dimensional case does not have a nice solution to correlations
|
||||
# Estimator for number of samples in one row/column of bins along each axis:
|
||||
n = max(1, n_samples^(1/N))
|
||||
|
||||
v = vs[dim]
|
||||
|
||||
if mode == :auto
|
||||
mode = :fd
|
||||
end
|
||||
|
||||
if mode == :sqrt # Square-root choice
|
||||
_cl(sqrt(n_samples))
|
||||
30
|
||||
elseif mode == :sqrt # Square-root choice
|
||||
_cl(sqrt(n))
|
||||
elseif mode == :sturges # Sturges' formula
|
||||
_cl(log2(n_samples) + 1)
|
||||
_cl(log2(n)) + 1
|
||||
elseif mode == :rice # Rice Rule
|
||||
_cl(2 * nd)
|
||||
_cl(2 * n^(1/3))
|
||||
elseif mode == :scott # Scott's normal reference rule
|
||||
_cl(_span(v) / (3.5 * std(v) / nd))
|
||||
_cl(_span(v) / (3.5 * std(v) / n^(1/3)))
|
||||
elseif mode == :fd # Freedman–Diaconis rule
|
||||
_cl(_span(v) / (2 * _iqr(v) / nd))
|
||||
elseif mode == :wand
|
||||
wand_edges(v) # this makes this function not type stable, but the type instability does not propagate
|
||||
_cl(_span(v) / (2 * _iqr(v) / n^(1/3)))
|
||||
else
|
||||
error("Unknown auto-binning mode $mode")
|
||||
end
|
||||
end::Int
|
||||
end
|
||||
|
||||
_hist_edge{N}(vs::NTuple{N,AbstractVector}, dim::Integer, binning::Integer) = StatsBase.histrange(vs[dim], binning, :left)
|
||||
@@ -557,13 +550,13 @@ end
|
||||
|
||||
|
||||
@recipe function f(::Type{Val{:histogram}}, x, y, z)
|
||||
seriestype := length(y) > 1e6 ? :stephist : :barhist
|
||||
seriestype := :barhist
|
||||
()
|
||||
end
|
||||
@deps histogram barhist
|
||||
|
||||
@recipe function f(::Type{Val{:barhist}}, x, y, z)
|
||||
h = _make_hist((y,), plotattributes[:bins], normed = plotattributes[:normalize], weights = plotattributes[:weights])
|
||||
h = _make_hist((y,), d[:bins], normed = d[:normalize], weights = d[:weights])
|
||||
x := h.edges[1]
|
||||
y := h.weights
|
||||
seriestype := :barbins
|
||||
@@ -572,7 +565,7 @@ end
|
||||
@deps barhist barbins
|
||||
|
||||
@recipe function f(::Type{Val{:stephist}}, x, y, z)
|
||||
h = _make_hist((y,), plotattributes[:bins], normed = plotattributes[:normalize], weights = plotattributes[:weights])
|
||||
h = _make_hist((y,), d[:bins], normed = d[:normalize], weights = d[:weights])
|
||||
x := h.edges[1]
|
||||
y := h.weights
|
||||
seriestype := :stepbins
|
||||
@@ -581,7 +574,7 @@ end
|
||||
@deps stephist stepbins
|
||||
|
||||
@recipe function f(::Type{Val{:scatterhist}}, x, y, z)
|
||||
h = _make_hist((y,), plotattributes[:bins], normed = plotattributes[:normalize], weights = plotattributes[:weights])
|
||||
h = _make_hist((y,), d[:bins], normed = d[:normalize], weights = d[:weights])
|
||||
x := h.edges[1]
|
||||
y := h.weights
|
||||
seriestype := :scatterbins
|
||||
@@ -597,11 +590,11 @@ end
|
||||
:bar => :barbins, :scatter => :scatterbins, :step => :stepbins,
|
||||
:steppost => :stepbins # :step can be mapped to :steppost in pre-processing
|
||||
)
|
||||
seriestype := get(st_map, plotattributes[:seriestype], plotattributes[:seriestype])
|
||||
seriestype := get(st_map, d[:seriestype], d[:seriestype])
|
||||
|
||||
if plotattributes[:seriestype] == :scatterbins
|
||||
if d[:seriestype] == :scatterbins
|
||||
# Workaround, error bars currently not set correctly by scatterbins
|
||||
edge, weights, xscale, yscale, baseline = _preprocess_binlike(plotattributes, h.edges[1], h.weights)
|
||||
edge, weights, xscale, yscale, baseline = _preprocess_binlike(d, h.edges[1], h.weights)
|
||||
xerror --> diff(h.edges[1])/2
|
||||
seriestype := :scatter
|
||||
(Plots._bin_centers(edge), weights)
|
||||
@@ -648,7 +641,7 @@ Plots.@deps bins2d heatmap
|
||||
|
||||
|
||||
@recipe function f(::Type{Val{:histogram2d}}, x, y, z)
|
||||
h = _make_hist((x, y), plotattributes[:bins], normed = plotattributes[:normalize], weights = plotattributes[:weights])
|
||||
h = _make_hist((x, y), d[:bins], normed = d[:normalize], weights = d[:weights])
|
||||
x := h.edges[1]
|
||||
y := h.edges[2]
|
||||
z := Surface(h.weights)
|
||||
@@ -669,7 +662,7 @@ end
|
||||
|
||||
@recipe function f(::Type{Val{:scatter3d}}, x, y, z)
|
||||
seriestype := :path3d
|
||||
if plotattributes[:markershape] == :none
|
||||
if d[:markershape] == :none
|
||||
markershape := :circle
|
||||
end
|
||||
linewidth := 0
|
||||
@@ -732,17 +725,17 @@ end
|
||||
# we will create a series of path segments, where each point represents one
|
||||
# side of an errorbar
|
||||
@recipe function f(::Type{Val{:yerror}}, x, y, z)
|
||||
error_style!(plotattributes)
|
||||
error_style!(d)
|
||||
markershape := :hline
|
||||
plotattributes[:x], plotattributes[:y] = error_coords(plotattributes[:x], plotattributes[:y], error_zipit(plotattributes[:yerror]))
|
||||
d[:x], d[:y] = error_coords(d[:x], d[:y], error_zipit(d[:yerror]))
|
||||
()
|
||||
end
|
||||
@deps yerror path
|
||||
|
||||
@recipe function f(::Type{Val{:xerror}}, x, y, z)
|
||||
error_style!(plotattributes)
|
||||
error_style!(d)
|
||||
markershape := :vline
|
||||
plotattributes[:y], plotattributes[:x] = error_coords(plotattributes[:y], plotattributes[:x], error_zipit(plotattributes[:xerror]))
|
||||
d[:y], d[:x] = error_coords(d[:y], d[:x], error_zipit(d[:xerror]))
|
||||
()
|
||||
end
|
||||
@deps xerror path
|
||||
@@ -841,9 +834,9 @@ end
|
||||
# function apply_series_recipe(d::KW, ::Type{Val{:quiver}})
|
||||
@recipe function f(::Type{Val{:quiver}}, x, y, z)
|
||||
if :arrow in supported_attrs()
|
||||
quiver_using_arrows(plotattributes)
|
||||
quiver_using_arrows(d)
|
||||
else
|
||||
quiver_using_hack(plotattributes)
|
||||
quiver_using_hack(d)
|
||||
end
|
||||
()
|
||||
end
|
||||
@@ -948,10 +941,10 @@ end
|
||||
rs, cs, zs = findnz(z.surf)
|
||||
xlim := ignorenan_extrema(cs)
|
||||
ylim := ignorenan_extrema(rs)
|
||||
if plotattributes[:markershape] == :none
|
||||
if d[:markershape] == :none
|
||||
markershape := :circle
|
||||
end
|
||||
if plotattributes[:markersize] == default(:markersize)
|
||||
if d[:markersize] == default(:markersize)
|
||||
markersize := 1
|
||||
end
|
||||
markerstrokewidth := 0
|
||||
|
||||
+35
-90
@@ -10,9 +10,6 @@ const FuncOrFuncs{F} = Union{F, Vector{F}, Matrix{F}}
|
||||
|
||||
all3D(d::KW) = trueOrAllTrue(st -> st in (:contour, :contourf, :heatmap, :surface, :wireframe, :contour3d, :image), get(d, :seriestype, :none))
|
||||
|
||||
# unknown
|
||||
convertToAnyVector(x, d::KW) = error("No user recipe defined for $(typeof(x))")
|
||||
|
||||
# missing
|
||||
convertToAnyVector(v::Void, d::KW) = Any[nothing], nothing
|
||||
|
||||
@@ -128,15 +125,15 @@ immutable SliceIt end
|
||||
z = z.data
|
||||
end
|
||||
|
||||
xs, _ = convertToAnyVector(x, plotattributes)
|
||||
ys, _ = convertToAnyVector(y, plotattributes)
|
||||
zs, _ = convertToAnyVector(z, plotattributes)
|
||||
xs, _ = convertToAnyVector(x, d)
|
||||
ys, _ = convertToAnyVector(y, d)
|
||||
zs, _ = convertToAnyVector(z, d)
|
||||
|
||||
fr = pop!(plotattributes, :fillrange, nothing)
|
||||
fr = pop!(d, :fillrange, nothing)
|
||||
fillranges, _ = if typeof(fr) <: Number
|
||||
([fr],nothing)
|
||||
else
|
||||
convertToAnyVector(fr, plotattributes)
|
||||
convertToAnyVector(fr, d)
|
||||
end
|
||||
mf = length(fillranges)
|
||||
|
||||
@@ -148,7 +145,7 @@ immutable SliceIt end
|
||||
if mx > 0 && my > 0 && mz > 0
|
||||
for i in 1:max(mx, my, mz)
|
||||
# add a new series
|
||||
di = copy(plotattributes)
|
||||
di = copy(d)
|
||||
xi, yi, zi = xs[mod1(i,mx)], ys[mod1(i,my)], zs[mod1(i,mz)]
|
||||
di[:x], di[:y], di[:z] = compute_xyz(xi, yi, zi)
|
||||
|
||||
@@ -174,7 +171,6 @@ _apply_type_recipe(d, v) = RecipesBase.apply_recipe(d, typeof(v), v)[1].args[1]
|
||||
# This sort of recipe should return a pair of functions... one to convert to number,
|
||||
# and one to format tick values.
|
||||
function _apply_type_recipe(d, v::AbstractArray)
|
||||
isempty(v) && return Float64[]
|
||||
args = RecipesBase.apply_recipe(d, typeof(v[1]), v[1])[1].args
|
||||
if length(args) == 2 && typeof(args[1]) <: Function && typeof(args[2]) <: Function
|
||||
numfunc, formatter = args
|
||||
@@ -206,11 +202,11 @@ _apply_type_recipe{T<:Union{Integer,AbstractFloat}}(d, v::AbstractArray{T}) = v
|
||||
# handle "type recipes" by converting inputs, and then either re-calling or slicing
|
||||
@recipe function f(x, y, z)
|
||||
did_replace = false
|
||||
newx = _apply_type_recipe(plotattributes, x)
|
||||
newx = _apply_type_recipe(d, x)
|
||||
x === newx || (did_replace = true)
|
||||
newy = _apply_type_recipe(plotattributes, y)
|
||||
newy = _apply_type_recipe(d, y)
|
||||
y === newy || (did_replace = true)
|
||||
newz = _apply_type_recipe(plotattributes, z)
|
||||
newz = _apply_type_recipe(d, z)
|
||||
z === newz || (did_replace = true)
|
||||
if did_replace
|
||||
newx, newy, newz
|
||||
@@ -220,9 +216,9 @@ _apply_type_recipe{T<:Union{Integer,AbstractFloat}}(d, v::AbstractArray{T}) = v
|
||||
end
|
||||
@recipe function f(x, y)
|
||||
did_replace = false
|
||||
newx = _apply_type_recipe(plotattributes, x)
|
||||
newx = _apply_type_recipe(d, x)
|
||||
x === newx || (did_replace = true)
|
||||
newy = _apply_type_recipe(plotattributes, y)
|
||||
newy = _apply_type_recipe(d, y)
|
||||
y === newy || (did_replace = true)
|
||||
if did_replace
|
||||
newx, newy
|
||||
@@ -231,7 +227,7 @@ end
|
||||
end
|
||||
end
|
||||
@recipe function f(y)
|
||||
newy = _apply_type_recipe(plotattributes, y)
|
||||
newy = _apply_type_recipe(d, y)
|
||||
if y !== newy
|
||||
newy
|
||||
else
|
||||
@@ -244,7 +240,7 @@ end
|
||||
@recipe function f(v1, v2, v3, v4, vrest...)
|
||||
did_replace = false
|
||||
newargs = map(v -> begin
|
||||
newv = _apply_type_recipe(plotattributes, v)
|
||||
newv = _apply_type_recipe(d, v)
|
||||
if newv !== v
|
||||
did_replace = true
|
||||
end
|
||||
@@ -271,13 +267,13 @@ function wrap_surfaces(d::KW)
|
||||
end
|
||||
end
|
||||
|
||||
@recipe f(n::Integer) = is3d(get(plotattributes,:seriestype,:path)) ? (SliceIt, n, n, n) : (SliceIt, n, n, nothing)
|
||||
@recipe f(n::Integer) = is3d(get(d,:seriestype,:path)) ? (SliceIt, n, n, n) : (SliceIt, n, n, nothing)
|
||||
|
||||
# return a surface if this is a 3d plot, otherwise let it be sliced up
|
||||
@recipe function f{T<:Union{Integer,AbstractFloat}}(mat::AMat{T})
|
||||
if all3D(plotattributes)
|
||||
if all3D(d)
|
||||
n,m = size(mat)
|
||||
wrap_surfaces(plotattributes)
|
||||
wrap_surfaces(d)
|
||||
SliceIt, 1:m, 1:n, Surface(mat)
|
||||
else
|
||||
SliceIt, nothing, mat, nothing
|
||||
@@ -286,10 +282,10 @@ end
|
||||
|
||||
# if a matrix is wrapped by Formatted, do similar logic, but wrap data with Surface
|
||||
@recipe function f{T<:AbstractMatrix}(fmt::Formatted{T})
|
||||
if all3D(plotattributes)
|
||||
if all3D(d)
|
||||
mat = fmt.data
|
||||
n,m = size(mat)
|
||||
wrap_surfaces(plotattributes)
|
||||
wrap_surfaces(d)
|
||||
SliceIt, 1:m, 1:n, Formatted(Surface(mat), fmt.formatter)
|
||||
else
|
||||
SliceIt, nothing, fmt, nothing
|
||||
@@ -329,7 +325,7 @@ end
|
||||
else
|
||||
seriestype := :heatmap
|
||||
yflip --> true
|
||||
z, plotattributes[:fillcolor] = replace_image_with_heatmap(mat)
|
||||
z, d[:fillcolor] = replace_image_with_heatmap(mat)
|
||||
SliceIt, 1:m, 1:n, Surface(z)
|
||||
end
|
||||
end
|
||||
@@ -359,28 +355,15 @@ end
|
||||
# function without range... use the current range of the x-axis
|
||||
|
||||
@recipe function f{F<:Function}(f::FuncOrFuncs{F})
|
||||
plt = plotattributes[:plot_object]
|
||||
plt = d[:plot_object]
|
||||
xmin, xmax = try
|
||||
axis_limits(plt[1][:xaxis])
|
||||
catch
|
||||
xm = tryrange(f, [-5,-1,0,0.01])
|
||||
xm, tryrange(f, filter(x->x>xm, [5,1,0.99, 0, -0.01]))
|
||||
-5, 5
|
||||
end
|
||||
|
||||
f, xmin, xmax
|
||||
end
|
||||
|
||||
# try some intervals over which the function may be defined
|
||||
function tryrange(F, vec)
|
||||
for v in vec
|
||||
try
|
||||
tmp = F(v)
|
||||
return v
|
||||
catch
|
||||
end
|
||||
end
|
||||
error("Function not defined over the given interval, $vec")
|
||||
end
|
||||
#
|
||||
# # --------------------------------------------------------------------
|
||||
# # 2 arguments
|
||||
@@ -421,7 +404,7 @@ end
|
||||
# seriestype := :path3d
|
||||
# end
|
||||
# end
|
||||
wrap_surfaces(plotattributes)
|
||||
wrap_surfaces(d)
|
||||
SliceIt, x, y, z
|
||||
end
|
||||
|
||||
@@ -431,7 +414,7 @@ end
|
||||
@recipe function f(x::AVec, y::AVec, zf::Function)
|
||||
# x = X <: Number ? sort(x) : x
|
||||
# y = Y <: Number ? sort(y) : y
|
||||
wrap_surfaces(plotattributes)
|
||||
wrap_surfaces(d)
|
||||
SliceIt, x, y, Surface(zf, x, y) # TODO: replace with SurfaceFunction when supported
|
||||
end
|
||||
|
||||
@@ -439,10 +422,10 @@ end
|
||||
# # surface-like... matrix grid
|
||||
|
||||
@recipe function f(x::AVec, y::AVec, z::AMat)
|
||||
if !like_surface(get(plotattributes, :seriestype, :none))
|
||||
plotattributes[:seriestype] = :contour
|
||||
if !like_surface(get(d, :seriestype, :none))
|
||||
d[:seriestype] = :contour
|
||||
end
|
||||
wrap_surfaces(plotattributes)
|
||||
wrap_surfaces(d)
|
||||
SliceIt, x, y, Surface(z)
|
||||
end
|
||||
|
||||
@@ -494,7 +477,7 @@ end
|
||||
@recipe f{R1<:Number,R2<:Number,R3<:Number}(xyz::Tuple{R1,R2,R3}) = [xyz[1]], [xyz[2]], [xyz[3]]
|
||||
|
||||
# these might be points+velocity, or OHLC or something else
|
||||
@recipe f{R1<:Number,R2<:Number,R3<:Number,R4<:Number}(xyuv::AVec{Tuple{R1,R2,R3,R4}}) = get(plotattributes,:seriestype,:path)==:ohlc ? OHLC[OHLC(t...) for t in xyuv] : unzip(xyuv)
|
||||
@recipe f{R1<:Number,R2<:Number,R3<:Number,R4<:Number}(xyuv::AVec{Tuple{R1,R2,R3,R4}}) = get(d,:seriestype,:path)==:ohlc ? OHLC[OHLC(t...) for t in xyuv] : unzip(xyuv)
|
||||
@recipe f{R1<:Number,R2<:Number,R3<:Number,R4<:Number}(xyuv::Tuple{R1,R2,R3,R4}) = [xyuv[1]], [xyuv[2]], [xyuv[3]], [xyuv[4]]
|
||||
|
||||
|
||||
@@ -533,57 +516,19 @@ splittable_kw(key, val::Tuple, lengthGroup) = all(splittable_kw.(key, val, lengt
|
||||
split_kw(key, val::AbstractArray, indices) = val[indices, fill(Colon(), ndims(val)-1)...]
|
||||
split_kw(key, val::Tuple, indices) = Tuple(split_kw(key, v, indices) for v in val)
|
||||
|
||||
function groupedvec2mat(x_ind, x, y::AbstractArray, groupby, def_val = y[1])
|
||||
y_mat = Array{promote_type(eltype(y), typeof(def_val))}(length(keys(x_ind)), length(groupby.groupLabels))
|
||||
fill!(y_mat, def_val)
|
||||
for i in 1:length(groupby.groupLabels)
|
||||
xi = x[groupby.groupIds[i]]
|
||||
yi = y[groupby.groupIds[i]]
|
||||
y_mat[getindex.(x_ind, xi), i] = yi
|
||||
end
|
||||
return y_mat
|
||||
end
|
||||
|
||||
groupedvec2mat(x_ind, x, y::Tuple, groupby) = Tuple(groupedvec2mat(x_ind, x, v, groupby) for v in y)
|
||||
|
||||
group_as_matrix(t) = false
|
||||
|
||||
# split the group into 1 series per group, and set the label and idxfilter for each
|
||||
@recipe function f(groupby::GroupBy, args...)
|
||||
lengthGroup = maximum(union(groupby.groupIds...))
|
||||
if !(group_as_matrix(args[1]))
|
||||
for (i,glab) in enumerate(groupby.groupLabels)
|
||||
@series begin
|
||||
label --> string(glab)
|
||||
idxfilter --> groupby.groupIds[i]
|
||||
for (key,val) in plotattributes
|
||||
if splittable_kw(key, val, lengthGroup)
|
||||
:($key) := split_kw(key, val, groupby.groupIds[i])
|
||||
end
|
||||
for (i,glab) in enumerate(groupby.groupLabels)
|
||||
@series begin
|
||||
label --> string(glab)
|
||||
idxfilter --> groupby.groupIds[i]
|
||||
for (key,val) in d
|
||||
if splittable_kw(key, val, lengthGroup)
|
||||
:($key) := split_kw(key, val, groupby.groupIds[i])
|
||||
end
|
||||
args
|
||||
end
|
||||
args
|
||||
end
|
||||
else
|
||||
g = args[1]
|
||||
if length(g.args) == 1
|
||||
x = zeros(Int64, lengthGroup)
|
||||
for indexes in groupby.groupIds
|
||||
x[indexes] = 1:length(indexes)
|
||||
end
|
||||
last_args = g.args
|
||||
else
|
||||
x = g.args[1]
|
||||
last_args = g.args[2:end]
|
||||
end
|
||||
x_u = unique(x)
|
||||
x_ind = Dict(zip(x_u, 1:length(x_u)))
|
||||
for (key,val) in plotattributes
|
||||
if splittable_kw(key, val, lengthGroup)
|
||||
:($key) := groupedvec2mat(x_ind, x, val, groupby)
|
||||
end
|
||||
end
|
||||
label --> reshape(groupby.groupLabels, 1, :)
|
||||
typeof(g)((x_u, (groupedvec2mat(x_ind, x, arg, groupby, NaN) for arg in last_args)...))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -539,83 +539,6 @@ xlims(sp_idx::Int = 1) = xlims(current(), sp_idx)
|
||||
ylims(sp_idx::Int = 1) = ylims(current(), sp_idx)
|
||||
zlims(sp_idx::Int = 1) = zlims(current(), sp_idx)
|
||||
|
||||
|
||||
function get_clims(sp::Subplot)
|
||||
zmin, zmax = Inf, -Inf
|
||||
for series in series_list(sp)
|
||||
for vals in (series[:z], series[:line_z], series[:marker_z], series[:fill_z])
|
||||
if (typeof(vals) <: AbstractSurface) && (eltype(vals.surf) <: Real)
|
||||
zmin, zmax = _update_clims(zmin, zmax, ignorenan_extrema(vals.surf)...)
|
||||
elseif (vals != nothing) && (eltype(vals) <: Real)
|
||||
zmin, zmax = _update_clims(zmin, zmax, ignorenan_extrema(vals)...)
|
||||
end
|
||||
end
|
||||
end
|
||||
clims = sp[:clims]
|
||||
if is_2tuple(clims)
|
||||
isfinite(clims[1]) && (zmin = clims[1])
|
||||
isfinite(clims[2]) && (zmax = clims[2])
|
||||
end
|
||||
return zmin < zmax ? (zmin, zmax) : (0.0, 0.0)
|
||||
end
|
||||
|
||||
_update_clims(zmin, zmax, emin, emax) = min(zmin, emin), max(zmax, emax)
|
||||
|
||||
function hascolorbar(series::Series)
|
||||
st = series[:seriestype]
|
||||
hascbar = st in (:heatmap, :contour)
|
||||
if series[:marker_z] != nothing || series[:line_z] != nothing || series[:fill_z] != nothing
|
||||
hascbar = true
|
||||
end
|
||||
# no colorbar if we are creating a surface LightSource
|
||||
if xor(st == :surface, series[:fill_z] != nothing)
|
||||
hascbar = true
|
||||
end
|
||||
return hascbar
|
||||
end
|
||||
|
||||
function hascolorbar(sp::Subplot)
|
||||
cbar = sp[:colorbar]
|
||||
hascbar = false
|
||||
if cbar != :none
|
||||
for series in series_list(sp)
|
||||
if hascolorbar(series)
|
||||
hascbar = true
|
||||
end
|
||||
end
|
||||
end
|
||||
hascbar
|
||||
end
|
||||
|
||||
function get_linecolor(sp::Subplot, series::Series, i::Int = 1)
|
||||
lc = series[:linecolor]
|
||||
lz = series[:line_z]
|
||||
if lz == nothing
|
||||
isa(lc, ColorGradient) ? lc : _cycle(lc, i)
|
||||
else
|
||||
cmin, cmax = get_clims(sp)
|
||||
grad = isa(lc, ColorGradient) ? lc : cgrad()
|
||||
grad[clamp((_cycle(lz, i) - cmin) / (cmax - cmin), 0, 1)]
|
||||
end
|
||||
end
|
||||
|
||||
function get_fillcolor(sp::Subplot, series::Series, i::Int = 1)
|
||||
fc = series[:fillcolor]
|
||||
fz = series[:fill_z]
|
||||
lz = series[:line_z]
|
||||
if fz == nothing && lz == nothing
|
||||
isa(fc, ColorGradient) ? fc : _cycle(fc, i)
|
||||
else
|
||||
cmin, cmax = get_clims(sp)
|
||||
grad = isa(fc, ColorGradient) ? fc : cgrad()
|
||||
if fz != nothing
|
||||
grad[clamp((_cycle(fz, i) - cmin) / (cmax - cmin), 0, 1)]
|
||||
elseif lz != nothing
|
||||
grad[clamp((_cycle(lz, i) - cmin) / (cmax - cmin), 0, 1)]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# ---------------------------------------------------------------
|
||||
|
||||
makekw(; kw...) = KW(kw)
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ default(size=(500,300))
|
||||
# TODO: use julia's Condition type and the wait() and notify() functions to initialize a Window, then wait() on a condition that
|
||||
# is referenced in a button press callback (the button clicked callback will call notify() on that condition)
|
||||
|
||||
const _current_plots_version = v"0.12.4"
|
||||
const _current_plots_version = v"0.12.3"
|
||||
|
||||
|
||||
function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = isinteractive(), sigma = [1,1], eps = 1e-2)
|
||||
|
||||
@@ -129,9 +129,6 @@ end
|
||||
@test Plots.ignorenan_extrema(axis) == (0.5, 7.5)
|
||||
end
|
||||
|
||||
@testset "NoFail" begin
|
||||
histogram([1, 0, 0, 0, 0, 0])
|
||||
end
|
||||
|
||||
# tests for preprocessing recipes
|
||||
|
||||
|
||||
Reference in New Issue
Block a user