Merge remote-tracking branch 'upstream/master'
t push
This commit is contained in:
commit
065ff48b15
@ -45,7 +45,7 @@ notifications:
|
||||
# uncomment the following lines to override the default test script
|
||||
script:
|
||||
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
|
||||
- julia -e 'using Pkg; Pkg.add(pwd()); Pkg.build("Plots")'
|
||||
- julia -e 'import Pkg; Pkg.add(Pkg.PackageSpec(path=pwd())); Pkg.build("Plots")'
|
||||
- julia test/travis_commands.jl
|
||||
# - julia -e 'Pkg.clone("ImageMagick"); Pkg.build("ImageMagick")'
|
||||
# - julia -e 'Pkg.clone("GR"); Pkg.build("GR")'
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
[](https://travis-ci.org/JuliaPlots/Plots.jl)
|
||||
[](https://ci.appveyor.com/project/mkborregaard/plots-jl)
|
||||
[](https://gitter.im/tbreloff/Plots.jl?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
<a href="http://docs.juliaplots.org/latest/" target="_blank"><img src="https://img.shields.io/badge/docs-latest-blue.svg" alt="Latest documentation"></a>
|
||||
<!-- [](http://pkg.julialang.org/?pkg=Plots&ver=0.3) -->
|
||||
<!-- [](http://pkg.julialang.org/?pkg=Plots&ver=0.4) -->
|
||||
<!-- [](https://coveralls.io/r/tbreloff/Plots.jl?branch=master) -->
|
||||
@ -21,5 +22,3 @@ Plots is a plotting API and toolset. My goals with the package are:
|
||||
- **Consistent**. Don't commit to one graphics package, use the same code everywhere.
|
||||
- **Lightweight**. Very few dependencies.
|
||||
- **Smart**. Attempts to figure out what you **want** it to do... not just what you **tell** it.
|
||||
|
||||
View the [full documentation](http://docs.juliaplots.org/latest).
|
||||
|
||||
@ -104,8 +104,6 @@ export
|
||||
rotate,
|
||||
rotate!,
|
||||
center,
|
||||
P2,
|
||||
P3,
|
||||
BezierCurve,
|
||||
|
||||
plotattr
|
||||
|
||||
@ -27,8 +27,8 @@ const _arg_desc = KW(
|
||||
:x => "Various. Input data. First Dimension",
|
||||
:y => "Various. Input data. Second Dimension",
|
||||
:z => "Various. Input data. Third Dimension. May be wrapped by a `Surface` for surface and heatmap types.",
|
||||
:marker_z => "AbstractVector, Function `f(x,y,z) -> z_value`, or nothing. z-values for each series data point, which correspond to the color to be used from a markercolor gradient.",
|
||||
:line_z => "AbstractVector, Function `f(x,y,z) -> z_value`, or nothing. z-values for each series line segment, which correspond to the color to be used from a linecolor gradient. Note that for N points, only the first N-1 values are used (one per line-segment).",
|
||||
:marker_z => "AbstractVector, Function `f(x,y,z) -> z_value`, or Function `f(x,y) -> z_value`, or nothing. z-values for each series data point, which correspond to the color to be used from a markercolor gradient.",
|
||||
:line_z => "AbstractVector, Function `f(x,y,z) -> z_value`, or Function `f(x,y) -> z_value`, or nothing. z-values for each series line segment, which correspond to the color to be used from a linecolor gradient. Note that for N points, only the first N-1 values are used (one per line-segment).",
|
||||
:fill_z => "Matrix{Float64} of the same size as z matrix, which specifies the color of the 3D surface; the default value is `nothing`.",
|
||||
:levels => "Integer, NTuple{2,Integer}. Number of levels (or x-levels/y-levels) for a contour type.",
|
||||
:orientation => "Symbol. Horizontal or vertical orientation for bar types. Values `:h`, `:hor`, `:horizontal` correspond to horizontal (sideways, anchored to y-axis), and `:v`, `:vert`, and `:vertical` correspond to vertical (the default).",
|
||||
|
||||
28
src/args.jl
28
src/args.jl
@ -1086,16 +1086,13 @@ function extractGroupArgs(vs::Tuple, args...)
|
||||
end
|
||||
|
||||
# allow passing NamedTuples for a named legend entry
|
||||
@require NamedTuples = "73a701b4-84e1-5df0-88ff-1968ee2ee8dc" begin
|
||||
legendEntryFromTuple(ns::NamedTuples.NamedTuple) =
|
||||
join(["$k = $v" for (k, v) in zip(keys(ns), values(ns))], ", ")
|
||||
legendEntryFromTuple(ns::NamedTuple) =
|
||||
join(["$k = $v" for (k, v) in pairs(ns)], ", ")
|
||||
|
||||
function extractGroupArgs(vs::NamedTuples.NamedTuple, args...)
|
||||
isempty(vs) && return GroupBy([""], [1:size(args[1],1)])
|
||||
NT = eval(:(NamedTuples.@NT($(keys(vs)...)))){map(eltype, vs)...}
|
||||
v = map(NT, vs...)
|
||||
extractGroupArgs(v, args...; legendEntry = legendEntryFromTuple)
|
||||
end
|
||||
function extractGroupArgs(vs::NamedTuple, args...)
|
||||
isempty(vs) && return GroupBy([""], [1:size(args[1],1)])
|
||||
v = map(NamedTuple{keys(vs)}∘tuple, values(vs)...)
|
||||
extractGroupArgs(v, args...; legendEntry = legendEntryFromTuple)
|
||||
end
|
||||
|
||||
# expecting a mapping of "group label" to "group indices"
|
||||
@ -1521,6 +1518,11 @@ function getSeriesRGBColor(c, sp::Subplot, n::Int)
|
||||
plot_color(c)
|
||||
end
|
||||
|
||||
function getSeriesRGBColor(c::AbstractArray, sp::Subplot, n::Int)
|
||||
@info "it is surprising that this function is called - please report a use case as a Plots issue"
|
||||
map(x->getSeriesRGBColor(x, sp, n), c)
|
||||
end
|
||||
|
||||
function ensure_gradient!(d::KW, csym::Symbol, asym::Symbol)
|
||||
if !isa(d[csym], ColorGradient)
|
||||
d[csym] = typeof(d[asym]) <: AbstractVector ? cgrad() : cgrad(alpha = d[asym])
|
||||
@ -1563,7 +1565,7 @@ function _update_series_attributes!(d::KW, plt::Plot, sp::Subplot)
|
||||
end
|
||||
|
||||
# update series color
|
||||
d[:seriescolor] = getSeriesRGBColor.(d[:seriescolor], Ref(sp), plotIndex)
|
||||
d[:seriescolor] = getSeriesRGBColor(d[:seriescolor], sp, plotIndex)
|
||||
|
||||
# update other colors
|
||||
for s in (:line, :marker, :fill)
|
||||
@ -1577,7 +1579,7 @@ function _update_series_attributes!(d::KW, plt::Plot, sp::Subplot)
|
||||
elseif d[csym] == :match
|
||||
plot_color(d[:seriescolor])
|
||||
else
|
||||
getSeriesRGBColor.(d[csym], Ref(sp), plotIndex)
|
||||
getSeriesRGBColor(d[csym], sp, plotIndex)
|
||||
end
|
||||
end
|
||||
|
||||
@ -1585,9 +1587,9 @@ function _update_series_attributes!(d::KW, plt::Plot, sp::Subplot)
|
||||
d[:markerstrokecolor] = if d[:markerstrokecolor] == :match
|
||||
plot_color(sp[:foreground_color_subplot])
|
||||
elseif d[:markerstrokecolor] == :auto
|
||||
getSeriesRGBColor.(d[:markercolor], Ref(sp), plotIndex)
|
||||
getSeriesRGBColor(d[:markercolor], sp, plotIndex)
|
||||
else
|
||||
getSeriesRGBColor.(d[:markerstrokecolor], Ref(sp), plotIndex)
|
||||
getSeriesRGBColor(d[:markerstrokecolor], sp, plotIndex)
|
||||
end
|
||||
|
||||
# if marker_z, fill_z or line_z are set, ensure we have a gradient
|
||||
|
||||
@ -387,7 +387,7 @@ end
|
||||
function _initialize_backend(::PyPlotBackend)
|
||||
@eval Main begin
|
||||
import PyPlot, PyCall
|
||||
import LaTeXStrings: latexstring
|
||||
import LaTeXStrings
|
||||
|
||||
export PyPlot
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@ const _gr_attr = merge_with_base_supported([
|
||||
:guidefontfamily, :guidefontsize, :guidefonthalign, :guidefontvalign,
|
||||
:guidefontrotation, :guidefontcolor,
|
||||
:grid, :gridalpha, :gridstyle, :gridlinewidth,
|
||||
:legend, :legendtitle, :colorbar,
|
||||
:legend, :legendtitle, :colorbar, :colorbar_title,
|
||||
:fill_z, :line_z, :marker_z, :levels,
|
||||
:ribbon, :quiver,
|
||||
:orientation,
|
||||
@ -421,6 +421,8 @@ const viewport_plotarea = zeros(4)
|
||||
# the size of the current plot in pixels
|
||||
const gr_plot_size = [600.0, 400.0]
|
||||
|
||||
const gr_colorbar_ratio = 0.1
|
||||
|
||||
function gr_viewport_from_bbox(sp::Subplot{GRBackend}, bb::BoundingBox, w, h, viewport_canvas)
|
||||
viewport = zeros(4)
|
||||
viewport[1] = viewport_canvas[2] * (left(bb) / w)
|
||||
@ -436,7 +438,7 @@ function gr_viewport_from_bbox(sp::Subplot{GRBackend}, bb::BoundingBox, w, h, vi
|
||||
viewport[4] = 0.5 * (vp[3] + vp[4] + extent)
|
||||
end
|
||||
if hascolorbar(sp)
|
||||
viewport[2] -= 0.1
|
||||
viewport[2] -= gr_colorbar_ratio
|
||||
end
|
||||
viewport
|
||||
end
|
||||
@ -483,6 +485,13 @@ function gr_colorbar(sp::Subplot, clims)
|
||||
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_font(guidefont(sp[:yaxis]))
|
||||
GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_TOP)
|
||||
GR.setcharup(-1, 0)
|
||||
gr_text(viewport_plotarea[2] + gr_colorbar_ratio,
|
||||
gr_view_ycenter(), sp[:colorbar_title])
|
||||
|
||||
gr_set_viewport_plotarea()
|
||||
end
|
||||
|
||||
@ -657,6 +666,9 @@ function _update_min_padding!(sp::Subplot{GRBackend})
|
||||
if sp[:yaxis][:guide] != ""
|
||||
leftpad += 4mm
|
||||
end
|
||||
if sp[:colorbar_title] != ""
|
||||
rightpad += 4mm
|
||||
end
|
||||
sp.minpad = Tuple(dpi * [leftpad, toppad, rightpad, bottompad])
|
||||
end
|
||||
|
||||
@ -1103,10 +1115,10 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
||||
GR.setspace(zmin, zmax, 0, 90)
|
||||
grad = isa(series[:fillcolor], ColorGradient) ? series[:fillcolor] : cgrad()
|
||||
colors = [plot_color(grad[clamp((zi-zmin) / (zmax-zmin), 0, 1)], series[:fillalpha]) for zi=z]
|
||||
rgba = map(c -> UInt32( round(Int, alpha(c) * 255) << 24 +
|
||||
round(Int, blue(c) * 255) << 16 +
|
||||
round(Int, green(c) * 255) << 8 +
|
||||
round(Int, red(c) * 255) ), colors)
|
||||
rgba = map(c -> UInt32( round(UInt, alpha(c) * 255) << 24 +
|
||||
round(UInt, blue(c) * 255) << 16 +
|
||||
round(UInt, green(c) * 255) << 8 +
|
||||
round(UInt, red(c) * 255) ), colors)
|
||||
w, h = length(x), length(y)
|
||||
GR.drawimage(xmin, xmax, ymax, ymin, w, h, rgba)
|
||||
|
||||
@ -1210,12 +1222,12 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
||||
xmin, xmax = ignorenan_extrema(series[:x]); ymin, ymax = ignorenan_extrema(series[:y])
|
||||
if eltype(z) <: Colors.AbstractGray
|
||||
grey = round.(UInt8, float(z) * 255)
|
||||
rgba = map(c -> UInt32( 0xff000000 + Int(c)<<16 + Int(c)<<8 + Int(c) ), grey)
|
||||
rgba = map(c -> UInt32( 0xff000000 + UInt(c)<<16 + UInt(c)<<8 + UInt(c) ), grey)
|
||||
else
|
||||
rgba = map(c -> UInt32( round(Int, alpha(c) * 255) << 24 +
|
||||
round(Int, blue(c) * 255) << 16 +
|
||||
round(Int, green(c) * 255) << 8 +
|
||||
round(Int, red(c) * 255) ), z)
|
||||
rgba = map(c -> UInt32( round(UInt, alpha(c) * 255) << 24 +
|
||||
round(UInt, blue(c) * 255) << 16 +
|
||||
round(UInt, green(c) * 255) << 8 +
|
||||
round(UInt, red(c) * 255) ), z)
|
||||
end
|
||||
GR.drawimage(xmin, xmax, ymax, ymin, w, h, rgba)
|
||||
end
|
||||
@ -1227,16 +1239,18 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
||||
gr_text(GR.wctondc(xi, yi)..., str)
|
||||
end
|
||||
|
||||
# draw the colorbar
|
||||
if cmap && st != :contour # special colorbar with steps is drawn for contours
|
||||
gr_set_line(1, :solid, yaxis[:foreground_color_axis])
|
||||
gr_set_transparency(1)
|
||||
gr_colorbar(sp, clims)
|
||||
end
|
||||
|
||||
GR.restorestate()
|
||||
end
|
||||
|
||||
# draw the colorbar
|
||||
GR.savestate()
|
||||
# special colorbar with steps is drawn for contours
|
||||
if cmap && any(series[:seriestype] != :contour for series in series_list(sp))
|
||||
gr_set_line(1, :solid, yaxis[:foreground_color_axis])
|
||||
gr_set_transparency(1)
|
||||
gr_colorbar(sp, clims)
|
||||
end
|
||||
GR.restorestate()
|
||||
|
||||
# add the legend
|
||||
if sp[:legend] != :none
|
||||
|
||||
@ -23,7 +23,7 @@ const _pgfplots_attr = merge_with_base_supported([
|
||||
:guide, :lims, :ticks, :scale, :flip, :rotation,
|
||||
:tickfont, :guidefont, :legendfont,
|
||||
:grid, :legend,
|
||||
:colorbar,
|
||||
:colorbar, :colorbar_title,
|
||||
:fill_z, :line_z, :marker_z, :levels,
|
||||
# :ribbon, :quiver, :arrow,
|
||||
# :orientation,
|
||||
@ -550,6 +550,7 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend})
|
||||
end
|
||||
@label colorbar_end
|
||||
|
||||
push!(style, "colorbar style={title=$(sp[:colorbar_title])}")
|
||||
o = axisf(; style = join(style, ","), kw...)
|
||||
|
||||
# add the series object to the PGFPlots.Axis
|
||||
|
||||
@ -236,16 +236,17 @@ function add_pyfixedformatter(cbar, vals::AVec)
|
||||
cbar[:update_ticks]()
|
||||
end
|
||||
|
||||
|
||||
function labelfunc(scale::Symbol, backend::PyPlotBackend)
|
||||
if scale == :log10
|
||||
x -> latexstring("10^{$x}")
|
||||
elseif scale == :log2
|
||||
x -> latexstring("2^{$x}")
|
||||
elseif scale == :ln
|
||||
x -> latexstring("e^{$x}")
|
||||
else
|
||||
string
|
||||
@require LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" begin
|
||||
function labelfunc(scale::Symbol, backend::PyPlotBackend)
|
||||
if scale == :log10
|
||||
x -> LaTeXStrings.latexstring("10^{$x}")
|
||||
elseif scale == :log2
|
||||
x -> LaTeXStrings.latexstring("2^{$x}")
|
||||
elseif scale == :ln
|
||||
x -> LaTeXStrings.latexstring("e^{$x}")
|
||||
else
|
||||
string
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -427,7 +427,7 @@ each line segment or marker in the plot.
|
||||
x = t .* cos.(θ)
|
||||
y = t .* sin.(θ)
|
||||
p1 = plot(x, y, line_z=t, linewidth=3, legend=false)
|
||||
p2 = scatter(x, y, marker_z=t, color=:bluesreds, legend=false)
|
||||
p2 = scatter(x, y, marker_z=(x,y)->x+y, color=:bluesreds, legend=false)
|
||||
plot(p1, p2)
|
||||
end)]
|
||||
),
|
||||
|
||||
@ -117,12 +117,12 @@ function _preprocess_userrecipe(kw::KW)
|
||||
# map marker_z if it's a Function
|
||||
if isa(get(kw, :marker_z, nothing), Function)
|
||||
# TODO: should this take y and/or z as arguments?
|
||||
kw[:marker_z] = map(kw[:marker_z], kw[:x], kw[:y], kw[:z])
|
||||
kw[:marker_z] = isa(kw[:z], Nothing) ? map(kw[:marker_z], kw[:x], kw[:y]) : map(kw[:marker_z], kw[:x], kw[:y], kw[:z])
|
||||
end
|
||||
|
||||
# map line_z if it's a Function
|
||||
if isa(get(kw, :line_z, nothing), Function)
|
||||
kw[:line_z] = map(kw[:line_z], kw[:x], kw[:y], kw[:z])
|
||||
kw[:line_z] = isa(kw[:z], Nothing) ? map(kw[:line_z], kw[:x], kw[:y]) : map(kw[:line_z], kw[:x], kw[:y], kw[:z])
|
||||
end
|
||||
|
||||
# convert a ribbon into a fillrange
|
||||
|
||||
@ -40,6 +40,9 @@ function plotattr(attribute::AbstractString)
|
||||
error("There is no attribute named $attribute")
|
||||
end
|
||||
|
||||
printnothing(x) = x
|
||||
printnothing(x::Nothing) = "nothing"
|
||||
|
||||
function plotattr(attrtype::Symbol, attribute::AbstractString)
|
||||
in(attrtype, keys(_attribute_defaults)) || ArgumentError("`attrtype` must match one of $(attrtypes())")
|
||||
|
||||
@ -49,14 +52,14 @@ function plotattr(attrtype::Symbol, attribute::AbstractString)
|
||||
first_period_idx = findfirst(isequal('.'), desc)
|
||||
typedesc = desc[1:first_period_idx-1]
|
||||
desc = strip(desc[first_period_idx+1:end])
|
||||
als = keys(filter((_,v)->v==attribute, _keyAliases)) |> collect |> sort
|
||||
als = keys(filter(x->x[2]==attribute, _keyAliases)) |> collect |> sort
|
||||
als = join(map(string,als), ", ")
|
||||
def = _attribute_defaults[attrtype][attribute]
|
||||
|
||||
|
||||
# Looks up the different elements and plots them
|
||||
println("$attribute ", typedesc == "" ? "" : "{$typedesc}", "\n",
|
||||
als == "" ? "" : "$als\n",
|
||||
"\n$desc\n",
|
||||
"$(attrtype) attribute, ", def == "" ? "" : " default: $def")
|
||||
println("$(printnothing(attribute)) ", typedesc == "" ? "" : "{$(printnothing(typedesc))}", "\n",
|
||||
als == "" ? "" : "$(printnothing(als))\n",
|
||||
"\n$(printnothing(desc))\n",
|
||||
"$(printnothing(attrtype)) attribute, ", def == "" ? "" : " default: $(printnothing(def))")
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user