Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b73dd46521 | |||
| 7bbb2070a7 | |||
| 8859518f2d | |||
| 7f063c71b5 | |||
| 1e9691a7c0 | |||
| e5269bcf95 | |||
| fdd76a6ca1 | |||
| d19525c269 | |||
| 593331dec2 | |||
| b780d90097 | |||
| 2f9ce790e4 | |||
| d8f4519b0c | |||
| 702e41f55d | |||
| 682ac29fcd | |||
| c6ce23d0af | |||
| 9ae7d2dd9d | |||
| 6ec05628d5 | |||
| f26ebdc2f1 | |||
| c97255fc08 | |||
| 9d1ede016b | |||
| 7eb8f2452c | |||
| 0a6e691222 | |||
| 238aca6a78 | |||
| 1f039b3adc | |||
| 219465d599 | |||
| 1963cee94a | |||
| ae43e05f6f | |||
| 5cd2ba7296 | |||
| 4a00018f25 | |||
| 32c725e770 | |||
| 4e2ee35125 | |||
| 35b0751714 | |||
| 28ebc0ccd8 | |||
| 3d693d88e0 | |||
| 6ddf31d465 | |||
| 5c1ea707ca | |||
| a6669f89a0 |
@@ -7,7 +7,7 @@ assignees: ''
|
||||
|
||||
---
|
||||
|
||||
Please search existing issues to avoid duplicates.
|
||||
<!-- Please search existing issues to avoid duplicates. -->
|
||||
|
||||
## Details
|
||||
|
||||
@@ -28,5 +28,5 @@ inspectdr | | |
|
||||
### Versions
|
||||
|
||||
Plots.jl version:
|
||||
Backend version:
|
||||
Backend version (`]st -m`):
|
||||
Output of `versioninfo()`:
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
name = "Plots"
|
||||
uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
|
||||
author = ["Tom Breloff (@tbreloff)"]
|
||||
version = "1.2.2"
|
||||
version = "1.3.3"
|
||||
|
||||
[deps]
|
||||
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
|
||||
@@ -44,7 +44,7 @@ PGFPlotsX = "1.2.0"
|
||||
PlotThemes = "2"
|
||||
PlotUtils = "1"
|
||||
RecipesBase = "1"
|
||||
RecipesPipeline = "0.1.3"
|
||||
RecipesPipeline = "0.1.7"
|
||||
Reexport = "0.2"
|
||||
Requires = "0.5, 1"
|
||||
Showoff = "0.3.1"
|
||||
|
||||
@@ -97,6 +97,7 @@ const _arg_desc = KW(
|
||||
:legendfontvalign => "Symbol. Font vertical alignment of legend entries: :vcenter, :top, :bottom or :center",
|
||||
:legendfontrotation => "Real. Font rotation of legend entries",
|
||||
:legendfontcolor => "Color Type. Font color of legend entries",
|
||||
:legendtitle => "String. Legend title.",
|
||||
:legendtitlefontfamily => "String or Symbol. Font family of the legend title.",
|
||||
:legendtitlefontsize => "Integer. Font pointsize the legend title.",
|
||||
:legendtitlefonthalign => "Symbol. Font horizontal alignment of the legend title: :hcenter, :left, :right or :center",
|
||||
|
||||
@@ -583,6 +583,7 @@ add_aliases(:fill_z, :fillz, :fz, :surfacecolor, :surfacecolour, :sc, :surfcolor
|
||||
add_aliases(:legend, :leg, :key)
|
||||
add_aliases(:legendtitle, :legend_title, :labeltitle, :label_title, :leg_title, :key_title)
|
||||
add_aliases(:colorbar, :cb, :cbar, :colorkey)
|
||||
add_aliases(:colorbar_title, :colorbartitle, :cb_title, :cbtitle, :cbartitle, :cbar_title, :colorkeytitle, :colorkey_title)
|
||||
add_aliases(:clims, :clim, :cbarlims, :cbar_lims, :climits, :color_limits)
|
||||
add_aliases(:smooth, :regression, :reg)
|
||||
add_aliases(:levels, :nlevels, :nlev, :levs)
|
||||
|
||||
+6
-2
@@ -190,11 +190,15 @@ function backend(sym::Symbol)
|
||||
end
|
||||
end
|
||||
|
||||
const _deprecated_backends = [:qwt, :winston, :bokeh, :gadfly, :immerse, :glvisualize]
|
||||
const _deprecated_backends = [:qwt, :winston, :bokeh, :gadfly, :immerse, :glvisualize, :pgfplots]
|
||||
|
||||
function warn_on_deprecated_backend(bsym::Symbol)
|
||||
if bsym in _deprecated_backends
|
||||
@warn("Backend $bsym has been deprecated.")
|
||||
if bsym == :pgfplots
|
||||
@warn("Backend $bsym has been deprecated. Use pgfplotsx instead.")
|
||||
else
|
||||
@warn("Backend $bsym has been deprecated.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
+4
-12
@@ -148,7 +148,7 @@ function gr_polyline(x, y, func = GR.polyline; arrowside = :none, arrowstyle = :
|
||||
end
|
||||
end
|
||||
|
||||
function gr_polyline3d(x, y, z, func = GR.polyline3d; arrowside = :none, arrowstyle = :simple)
|
||||
function gr_polyline3d(x, y, z, func = GR.polyline3d)
|
||||
iend = 0
|
||||
n = length(x)
|
||||
while iend < n-1
|
||||
@@ -176,14 +176,6 @@ function gr_polyline3d(x, y, z, func = GR.polyline3d; arrowside = :none, arrowst
|
||||
# if we found a start and end, draw the line segment, otherwise we're done
|
||||
if istart > 0 && iend > 0
|
||||
func(x[istart:iend], y[istart:iend], z[istart:iend])
|
||||
if arrowside in (:head,:both)
|
||||
gr_set_arrowstyle(arrowstyle)
|
||||
GR.drawarrow(x[iend-1], y[iend-1], z[iend-1], x[iend], y[iend], z[iend])
|
||||
end
|
||||
if arrowside in (:tail,:both)
|
||||
gr_set_arrowstyle(arrowstyle)
|
||||
GR.drawarrow(x[istart+1], y[istart+1], z[istart+1], x[istart], y[istart], z[istart])
|
||||
end
|
||||
else
|
||||
break
|
||||
end
|
||||
@@ -749,9 +741,9 @@ function gr_get_ticks_size(ticks, rot)
|
||||
return w, h
|
||||
end
|
||||
|
||||
gr_tick_label(axis,label) = (axis[:formatter] in (:scientific, :auto)) ?
|
||||
gr_convert_sci_tick_label(label) :
|
||||
label
|
||||
gr_tick_label(axis, label) =
|
||||
(axis[:formatter] in (:scientific, :auto)) ? gr_convert_sci_tick_label(string(label)) :
|
||||
string(label)
|
||||
|
||||
function gr_convert_sci_tick_label(label)
|
||||
caret_split = split(label,'^')
|
||||
|
||||
+100
-73
@@ -136,17 +136,12 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
||||
bgc_inside = plot_color(sp[:background_color_inside])
|
||||
bgc_inside_a = alpha(bgc_inside)
|
||||
axis_opt = PGFPlotsX.Options(
|
||||
"point meta max" => get_clims(sp)[2],
|
||||
"point meta min" => get_clims(sp)[1],
|
||||
"legend cell align" => "left",
|
||||
"title" => sp[:title],
|
||||
"title style" => PGFPlotsX.Options(
|
||||
"at" => if title_loc == :left
|
||||
"{(0,1)}"
|
||||
elseif title_loc == :right
|
||||
"{(1,1)}"
|
||||
elseif title_loc isa Tuple
|
||||
"{$(string(title_loc))}"
|
||||
else
|
||||
"{(0.5,1)}"
|
||||
end,
|
||||
pgfx_get_title_pos(title_loc)...,
|
||||
"font" => pgfx_font(
|
||||
sp[:titlefontsize],
|
||||
pgfx_thickness_scaling(sp),
|
||||
@@ -184,12 +179,7 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
||||
sp_height > 0 * mm ? push!(axis_opt, "height" => string(axis_height)) :
|
||||
nothing
|
||||
# legend position
|
||||
if sp[:legend] isa Tuple
|
||||
x, y = sp[:legend]
|
||||
push!(axis_opt["legend style"], "at={($x, $y)}")
|
||||
else
|
||||
push!(axis_opt["legend style"], pgfx_get_legend_pos(sp[:legend])...)
|
||||
end
|
||||
push!(axis_opt["legend style"], pgfx_get_legend_pos(sp[:legend])...)
|
||||
for letter in (:x, :y, :z)
|
||||
if letter != :z || RecipesPipeline.is3d(sp)
|
||||
pgfx_axis!(axis_opt, sp, letter)
|
||||
@@ -206,41 +196,48 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
||||
# As it is likely that all series within the same axis use the same
|
||||
# colormap this should not cause any problem.
|
||||
for series in series_list(sp)
|
||||
if hascolorbar(series)
|
||||
cg = get_colorgradient(series)
|
||||
cm = pgfx_colormap(get_colorgradient(series))
|
||||
PGFPlotsX.push_preamble!(
|
||||
pgfx_plot.the_plot,
|
||||
"""\\pgfplotsset{
|
||||
colormap={plots$(sp.attr[:subplot_index])}{$cm},
|
||||
}""",
|
||||
)
|
||||
if hascolorbar(series)
|
||||
cg = get_colorgradient(series)
|
||||
cm = pgfx_colormap(get_colorgradient(series))
|
||||
PGFPlotsX.push_preamble!(
|
||||
pgfx_plot.the_plot,
|
||||
"""\\pgfplotsset{
|
||||
colormap={plots$(sp.attr[:subplot_index])}{$cm},
|
||||
}""",
|
||||
)
|
||||
push!(axis_opt, "colormap name" => "plots$(sp.attr[:subplot_index])")
|
||||
if cg isa PlotUtils.CategoricalColorGradient
|
||||
push!(
|
||||
axis_opt,
|
||||
"colorbar" => nothing,
|
||||
"colormap name" => "plots$(sp.attr[:subplot_index])",
|
||||
"colormap access" => "piecewise const",
|
||||
"colorbar sampled" => nothing,
|
||||
)
|
||||
if cg isa PlotUtils.CategoricalColorGradient
|
||||
push!(
|
||||
axis_opt,
|
||||
"colormap access" => "piecewise const",
|
||||
"colorbar sampled" => nothing,
|
||||
)
|
||||
end
|
||||
# goto is needed to break out of col and series for
|
||||
@goto colorbar_end
|
||||
end
|
||||
# goto is needed to break out of col and series for
|
||||
@goto colorbar_end
|
||||
end
|
||||
end
|
||||
@label colorbar_end
|
||||
|
||||
push!(
|
||||
axis_opt,
|
||||
"colorbar style" => PGFPlotsX.Options(
|
||||
if hascolorbar(sp)
|
||||
colorbar_style = PGFPlotsX.Options(
|
||||
"title" => sp[:colorbar_title],
|
||||
),
|
||||
"point meta max" => get_clims(sp)[2],
|
||||
"point meta min" => get_clims(sp)[1],
|
||||
)
|
||||
"xticklabel style" => pgfx_get_ticklabel_style(sp, sp[:xaxis]),
|
||||
"yticklabel style" => pgfx_get_ticklabel_style(sp, sp[:yaxis]),
|
||||
)
|
||||
if sp[:colorbar] === :top
|
||||
push!(colorbar_style,
|
||||
"at" => string((0.5, 1.05)),
|
||||
"anchor" => "south",
|
||||
"xticklabel pos" => "upper",
|
||||
)
|
||||
end
|
||||
push!(
|
||||
axis_opt,
|
||||
string("colorbar", pgfx_get_colorbar_pos(sp[:colorbar])) => nothing,
|
||||
"colorbar style" => colorbar_style,
|
||||
)
|
||||
end
|
||||
if RecipesPipeline.is3d(sp)
|
||||
azim, elev = sp[:camera]
|
||||
push!(axis_opt, "view" => (azim, elev))
|
||||
@@ -288,7 +285,7 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
||||
extra_series = wraptuple(pop!(extra_series_opt,:add))
|
||||
end
|
||||
series_opt = merge(series_opt, PGFPlotsX.Options(extra_series_opt...))
|
||||
if RecipesPipeline.is3d(series) || st == :heatmap
|
||||
if RecipesPipeline.is3d(series) || st in (:heatmap, :contour)
|
||||
series_func = PGFPlotsX.Plot3
|
||||
else
|
||||
series_func = PGFPlotsX.Plot
|
||||
@@ -297,7 +294,7 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
||||
!isfilledcontour(series) && series[:ribbon] === nothing
|
||||
push!(series_opt, "area legend" => nothing)
|
||||
end
|
||||
if st == :heatmap
|
||||
if st in (:heatmap, :contour)
|
||||
push!(axis.options, "view" => "{0}{90}")
|
||||
end
|
||||
# treat segments
|
||||
@@ -342,12 +339,13 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
||||
end
|
||||
segment_opt = merge(segment_opt, pgfx_marker(opt, i))
|
||||
end
|
||||
if st == :shape || isfilledcontour(series)
|
||||
if st == :shape
|
||||
segment_opt = merge(segment_opt, pgfx_fillstyle(opt, i))
|
||||
end
|
||||
# add fillrange
|
||||
if sf !== nothing &&
|
||||
!isfilledcontour(series) && series[:ribbon] === nothing
|
||||
!isfilledcontour(series) &&
|
||||
series[:ribbon] === nothing
|
||||
if sf isa Number || sf isa AVec
|
||||
pgfx_fillrange_series!(
|
||||
axis,
|
||||
@@ -596,8 +594,8 @@ function pgfx_series_coordinates!(
|
||||
xs, ys, zs = collect(args)
|
||||
push!(
|
||||
segment_opt,
|
||||
"contour filled" => PGFPlotsX.Options("labels" => opt[:contour_labels]),
|
||||
"point meta" => "explicit",
|
||||
"contour filled" => PGFPlotsX.Options(), # labels not supported
|
||||
"patch type" => "bilinear",
|
||||
"shader" => "flat",
|
||||
)
|
||||
if opt[:levels] isa Number
|
||||
@@ -606,17 +604,7 @@ function pgfx_series_coordinates!(
|
||||
push!(segment_opt["contour filled"], "levels" => opt[:levels])
|
||||
end
|
||||
|
||||
cs = join(
|
||||
[
|
||||
join(["($x, $y) [$(zs[j, i])]" for (j, x) in enumerate(xs)], " ") for (i, y) in enumerate(ys)
|
||||
],
|
||||
"\n\n",
|
||||
)
|
||||
"""
|
||||
coordinates {
|
||||
$cs
|
||||
};
|
||||
"""
|
||||
PGFPlotsX.Coordinates(args...)
|
||||
end
|
||||
##
|
||||
pgfx_get_linestyle(k) = get(
|
||||
@@ -655,6 +643,26 @@ pgfx_get_marker(k) = get(
|
||||
"*",
|
||||
)
|
||||
|
||||
pgfx_get_xguide_pos(k) = get(
|
||||
(
|
||||
top = "at={(0.5,1)},above,",
|
||||
right = "at={(ticklabel* cs:1.02)}, anchor=west,",
|
||||
left = "at={(ticklabel* cs:-0.02)}, anchor=east,",
|
||||
),
|
||||
k,
|
||||
"at={(ticklabel cs:0.5)}, anchor=near ticklabel"
|
||||
)
|
||||
|
||||
pgfx_get_yguide_pos(k) = get(
|
||||
(
|
||||
top = "at={(ticklabel* cs:1.02)}, anchor=south",
|
||||
right = "at={(1,0.5)},below,",
|
||||
bottom = "at={(ticklabel* cs:-0.02)}, anchor=north,",
|
||||
),
|
||||
k,
|
||||
"at={(ticklabel cs:0.5)}, anchor=near ticklabel"
|
||||
)
|
||||
|
||||
pgfx_get_legend_pos(k) = get(
|
||||
(
|
||||
top = ("at" => string((0.5, 0.98)), "anchor" => "north"),
|
||||
@@ -677,6 +685,33 @@ pgfx_get_legend_pos(k) = get(
|
||||
Symbol(k),
|
||||
("at" => string((1.02, 1)), "anchor" => "north west"),
|
||||
)
|
||||
pgfx_get_legend_pos(t::Tuple) = ("at" => "{$(string(t))}", "anchor" => "north west")
|
||||
pgfx_get_legend_pos(nt::NamedTuple) = ("at" => "{$(string(nt.at))}", "anchor" => string(nt.anchor))
|
||||
|
||||
pgfx_get_colorbar_pos(s) =
|
||||
get((left = " left", bottom = " horizontal", top = " horizontal"), s, "")
|
||||
pgfx_get_colorbar_pos(b::Bool) = ""
|
||||
|
||||
pgfx_get_title_pos(s) =
|
||||
get((
|
||||
left = ("at" => "{(0,1)}", "anchor" => "south west"),
|
||||
right = ("at" => "{(1,1)}", "anchor" => "south east"),
|
||||
), s,
|
||||
("at" => "{(0.5,1)}", "anchor" => "south"))
|
||||
pgfx_get_title_pos(t::Tuple) = ("at" => "{$(string(t))}", "anchor" => "south")
|
||||
pgfx_get_title_pos(nt::NamedTuple) = ("at" => "{$(string(nt.at))}", "anchor" => string(nt.anchor))
|
||||
|
||||
function pgfx_get_ticklabel_style(sp, axis)
|
||||
cstr = plot_color(axis[:tickfontcolor])
|
||||
return PGFPlotsX.Options(
|
||||
"font" => pgfx_font(
|
||||
axis[:tickfontsize], pgfx_thickness_scaling(sp)
|
||||
),
|
||||
"color" => cstr,
|
||||
"draw opacity" => alpha(cstr),
|
||||
"rotate" => axis[:tickfontrotation],
|
||||
)
|
||||
end
|
||||
|
||||
## --------------------------------------------------------------------------------------
|
||||
# Generates a colormap for pgfplots based on a ColorGradient
|
||||
@@ -1018,10 +1053,10 @@ function pgfx_axis!(opt::PGFPlotsX.Options, sp::Subplot, letter)
|
||||
|
||||
# axis label position
|
||||
labelpos = ""
|
||||
if letter == :x && axis[:guide_position] == :top
|
||||
labelpos = "at={(0.5,1)},above,"
|
||||
elseif letter == :y && axis[:guide_position] == :right
|
||||
labelpos = "at={(1,0.5)},below,"
|
||||
if letter == :x
|
||||
labelpos = pgfx_get_xguide_pos(axis[:guide_position])
|
||||
elseif letter == :y
|
||||
labelpos = pgfx_get_yguide_pos(axis[:guide_position])
|
||||
end
|
||||
|
||||
# Add label font
|
||||
@@ -1114,17 +1149,8 @@ function pgfx_axis!(opt::PGFPlotsX.Options, sp::Subplot, letter)
|
||||
string(letter, "tick align") =>
|
||||
(axis[:tick_direction] == :out ? "outside" : "inside"),
|
||||
)
|
||||
cstr = plot_color(axis[:tickfontcolor])
|
||||
α = alpha(cstr)
|
||||
push!(
|
||||
opt,
|
||||
string(letter, "ticklabel style") => PGFPlotsX.Options(
|
||||
"font" =>
|
||||
pgfx_font(axis[:tickfontsize], pgfx_thickness_scaling(sp)),
|
||||
"color" => cstr,
|
||||
"draw opacity" => α,
|
||||
"rotate" => axis[:tickfontrotation],
|
||||
),
|
||||
opt, string(letter, "ticklabel style") => pgfx_get_ticklabel_style(sp, axis)
|
||||
)
|
||||
push!(
|
||||
opt,
|
||||
@@ -1212,6 +1238,7 @@ function pgfx_axis!(opt::PGFPlotsX.Options, sp::Subplot, letter)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
# --------------------------------------------------------------------------------------
|
||||
# display calls this and then _display, its called 3 times for plot(1:5)
|
||||
# Set the (left, top, right, bottom) minimum padding around the plot area
|
||||
|
||||
@@ -336,7 +336,7 @@ function plotly_layout(plt::Plot)
|
||||
plotattributes_out[:hovermode] = "none"
|
||||
end
|
||||
|
||||
plotattributes_out
|
||||
plotattributes_out = recursive_merge(plotattributes_out, plt.attr[:extra_plot_kwargs])
|
||||
end
|
||||
|
||||
function plotly_layout_json(plt::Plot)
|
||||
@@ -810,9 +810,14 @@ html_body(plt::Plot{PlotlyBackend}) = plotly_html_body(plt)
|
||||
const ijulia_initialized = Ref(false)
|
||||
|
||||
function plotly_html_head(plt::Plot)
|
||||
local_file = ("file://" * plotly_local_file_path)
|
||||
local_file = ("file:///" * plotly_local_file_path)
|
||||
plotly =
|
||||
use_local_dependencies[] ? local_file : "https://cdn.plot.ly/plotly-latest.min.js"
|
||||
|
||||
include_mathjax = get(plt[:extra_plot_kwargs], :include_mathjax, "")
|
||||
mathjax_file = include_mathjax != "cdn" ? ("file://" * include_mathjax) : "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML"
|
||||
mathjax_head = include_mathjax == "" ? "" : "<script src=\"$mathjax_file\"></script>\n\t\t"
|
||||
|
||||
if isijulia() && !ijulia_initialized[]
|
||||
# using requirejs seems to be key to load a js depency in IJulia!
|
||||
# https://requirejs.org/docs/start.html
|
||||
@@ -826,7 +831,7 @@ function plotly_html_head(plt::Plot)
|
||||
""")
|
||||
ijulia_initialized[] = true
|
||||
end
|
||||
return "<script src=$(repr(plotly))></script>"
|
||||
return "$mathjax_head<script src=$(repr(plotly))></script>"
|
||||
end
|
||||
|
||||
function plotly_html_body(plt, style = nothing)
|
||||
|
||||
+35
-14
@@ -13,6 +13,7 @@ append!(Base.Multimedia.displays, otherdisplays)
|
||||
pycolors = PyPlot.pyimport("matplotlib.colors")
|
||||
pypath = PyPlot.pyimport("matplotlib.path")
|
||||
mplot3d = PyPlot.pyimport("mpl_toolkits.mplot3d")
|
||||
axes_grid1 = PyPlot.pyimport("mpl_toolkits.axes_grid1")
|
||||
pypatches = PyPlot.pyimport("matplotlib.patches")
|
||||
pyfont = PyPlot.pyimport("matplotlib.font_manager")
|
||||
pyticker = PyPlot.pyimport("matplotlib.ticker")
|
||||
@@ -589,6 +590,12 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
||||
push!(handles, handle)
|
||||
else
|
||||
# do a normal scatter plot
|
||||
|
||||
# Add depthshade option for 3d plots
|
||||
if RecipesPipeline.is3d(sp)
|
||||
extrakw[:depthshade] = get(series[:extra_kwargs], :depthshade, false)
|
||||
end
|
||||
|
||||
handle = ax."scatter"(xyargs...;
|
||||
label = series[:label],
|
||||
zorder = series[:series_plotindex] + 0.5,
|
||||
@@ -603,14 +610,16 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
||||
end
|
||||
|
||||
if st == :hexbin
|
||||
handle = ax."hexbin"(x, y;
|
||||
handle = ax."hexbin"(x, y,
|
||||
label = series[:label],
|
||||
zorder = series[:series_plotindex],
|
||||
gridsize = series[:bins],
|
||||
C = series[:weights],
|
||||
gridsize = series[:bins]==:auto ? 100 : series[:bins], # 100 is the default value
|
||||
linewidths = py_thickness_scale(plt, series[:linewidth]),
|
||||
edgecolors = py_color(get_linecolor(series)),
|
||||
alpha = series[:fillalpha],
|
||||
cmap = py_fillcolormap(series), # applies to the pcolorfast object
|
||||
extrakw...
|
||||
zorder = series[:series_plotindex],
|
||||
# extrakw... # We are not supporting clims for hexbin as calculation of bins is not trivial
|
||||
)
|
||||
push!(handles, handle)
|
||||
end
|
||||
@@ -995,12 +1004,27 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
|
||||
end
|
||||
kw[:spacing] = "proportional"
|
||||
|
||||
# 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...)
|
||||
|
||||
if RecipesPipeline.is3d(sp)
|
||||
cbax = fig."add_axes"([0.9, 0.1, 0.03, 0.8])
|
||||
cb = fig."colorbar"(handle; cax=cbax, kw...)
|
||||
else
|
||||
# divider approach works only with 2d plots
|
||||
divider = axes_grid1.make_axes_locatable(ax)
|
||||
# width = axes_grid1.axes_size.AxesY(ax, aspect=1.0 / 3.5)
|
||||
# pad = axes_grid1.axes_size.Fraction(0.5, width) # Colorbar is spaced 0.5 of its size away from the ax
|
||||
# cbax = divider.append_axes("right", size=width, pad=pad) # This approach does not work well in subplots
|
||||
cbax = divider.append_axes("right", size="5%", pad="2.5%") # Reasonable value works most of the usecases
|
||||
cb = fig."colorbar"(handle; cax=cbax, kw...)
|
||||
end
|
||||
|
||||
cb."set_label"(sp[:colorbar_title],size=py_thickness_scale(plt, sp[:yaxis][:guidefontsize]),family=sp[:yaxis][:guidefontfamily], color = py_color(sp[:yaxis][:guidefontcolor]))
|
||||
|
||||
# cb."formatter".set_useOffset(false) # This for some reason does not work, must be a pyplot bug, instead this is a workaround:
|
||||
cb."formatter".set_powerlimits((-Inf, Inf))
|
||||
cb."update_ticks"()
|
||||
|
||||
for lab in cb."ax"."yaxis"."get_ticklabels"()
|
||||
lab."set_fontsize"(py_thickness_scale(plt, sp[:yaxis][:tickfontsize]))
|
||||
lab."set_family"(sp[:yaxis][:tickfontfamily])
|
||||
@@ -1212,7 +1236,7 @@ function _update_min_padding!(sp::Subplot{PyPlotBackend})
|
||||
# optionally add the width of colorbar labels and colorbar to rightpad
|
||||
if haskey(sp.attr, :cbar_ax)
|
||||
bb = py_bbox(sp.attr[:cbar_handle]."ax"."get_yticklabels"())
|
||||
sp.attr[:cbar_width] = _cbar_width + width(bb) + 2.3mm + (sp[:colorbar_title] == "" ? 0px : 30px)
|
||||
sp.attr[:cbar_width] = _cbar_width + width(bb) + (sp[:colorbar_title] == "" ? 0px : 30px)
|
||||
rightpad = rightpad + sp.attr[:cbar_width]
|
||||
end
|
||||
|
||||
@@ -1373,13 +1397,10 @@ function _update_plot_object(plt::Plot{PyPlotBackend})
|
||||
pcts = bbox_to_pcts(sp.plotarea, figw, figh)
|
||||
ax."set_position"(pcts)
|
||||
|
||||
# set the cbar position if there is one
|
||||
if haskey(sp.attr, :cbar_ax)
|
||||
if haskey(sp.attr, :cbar_ax) && RecipesPipeline.is3d(sp) # 2D plots are completely handled by axis dividers
|
||||
cbw = sp.attr[:cbar_width]
|
||||
# this is the bounding box of just the colors of the colorbar (not labels)
|
||||
ex = sp[:zaxis][:extrema]
|
||||
has_toplabel = !(1e-7 < max(abs(ex.emax), abs(ex.emin)) < 1e7)
|
||||
cb_bbox = BoundingBox(right(sp.bbox)-cbw+1mm, top(sp.bbox) + (has_toplabel ? 4mm : 2mm), _cbar_width-1mm, height(sp.bbox) - (has_toplabel ? 6mm : 4mm))
|
||||
cb_bbox = BoundingBox(right(sp.bbox)-cbw - 2mm, top(sp.bbox) + 2mm, _cbar_width-1mm, height(sp.bbox) - 4mm)
|
||||
pcts = bbox_to_pcts(cb_bbox, figw, figh)
|
||||
sp.attr[:cbar_ax]."set_position"(pcts)
|
||||
end
|
||||
|
||||
@@ -998,13 +998,11 @@ _backend_skips = Dict(
|
||||
6, # images
|
||||
10, # histogram2d
|
||||
16, # pgfplots thinks the upper panel is too small
|
||||
22, # contourf
|
||||
25, # @df
|
||||
30, # @df
|
||||
31, # animation
|
||||
32, # spy
|
||||
38, # histogram2d
|
||||
45, # wireframe
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ function __init__()
|
||||
end
|
||||
|
||||
@require PGFPlots = "3b7a836e-365b-5785-a47d-02c71176b4aa" begin
|
||||
fn = joinpath(@__DIR__, "backends", "pgfplots.jl")
|
||||
fn = joinpath(@__DIR__, "backends", "deprecated", "pgfplots.jl")
|
||||
include(fn)
|
||||
@require Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" Revise.track(Plots, fn)
|
||||
end
|
||||
|
||||
@@ -155,8 +155,23 @@ RecipesPipeline.type_alias(plt::Plot) = get(_typeAliases, st, st)
|
||||
function RecipesPipeline.plot_setup!(plt::Plot, plotattributes, kw_list)
|
||||
_plot_setup(plt, plotattributes, kw_list)
|
||||
_subplot_setup(plt, plotattributes, kw_list)
|
||||
return nothing
|
||||
end
|
||||
|
||||
function RecipesPipeline.process_sliced_series_attributes!(plt::Plots.Plot, kw_list)
|
||||
# swap errors
|
||||
err_inds = findall(kw -> get(kw, :seriestype, :path) in (:xerror, :yerror, :zerror), kw_list)
|
||||
for ind in err_inds
|
||||
if get(kw_list[ind-1],:seriestype,:path) == :scatter
|
||||
tmp = copy(kw_list[ind])
|
||||
kw_list[ind] = copy(kw_list[ind-1])
|
||||
kw_list[ind-1] = tmp
|
||||
end
|
||||
end
|
||||
return nothing
|
||||
end
|
||||
|
||||
|
||||
# TODO: Should some of this logic be moved to RecipesPipeline?
|
||||
function _plot_setup(plt::Plot, plotattributes::AKW, kw_list::Vector{KW})
|
||||
# merge in anything meant for the Plot
|
||||
@@ -274,6 +289,7 @@ function RecipesPipeline.slice_series_attributes!(plt::Plot, kw_list, kw)
|
||||
# in series attributes given as vector with one element per series,
|
||||
# select the value for current series
|
||||
_slice_series_args!(kw, plt, sp, series_idx(kw_list, kw))
|
||||
return nothing
|
||||
end
|
||||
|
||||
RecipesPipeline.series_defaults(plt::Plot) = _series_defaults # in args.jl
|
||||
|
||||
+4
-3
@@ -71,8 +71,9 @@ const POTENTIAL_VECTOR_ARGUMENTS = [
|
||||
:marker_z,
|
||||
:markerstrokecolor,
|
||||
:markerstrokealpha,
|
||||
:xerror,
|
||||
:yerror,
|
||||
:yerror,
|
||||
:zerror,
|
||||
:series_annotations,
|
||||
:fillrange,
|
||||
]
|
||||
@@ -459,7 +460,7 @@ end
|
||||
@deps plots_heatmap shape
|
||||
is_3d(::Type{Val{:plots_heatmap}}) = true
|
||||
RecipesPipeline.is_surface(::Type{Val{:plots_heatmap}}) = true
|
||||
|
||||
RecipesPipeline.is_surface(::Type{Val{:hexbin}}) = true
|
||||
# ---------------------------------------------------------------------------
|
||||
# Histograms
|
||||
|
||||
@@ -1027,7 +1028,7 @@ end
|
||||
|
||||
function error_style!(plotattributes::AKW)
|
||||
plotattributes[:seriestype] = :path
|
||||
plotattributes[:linecolor] = plotattributes[:markerstrokecolor]
|
||||
plotattributes[:markercolor] = plotattributes[:markerstrokecolor]
|
||||
plotattributes[:linewidth] = plotattributes[:markerstrokewidth]
|
||||
plotattributes[:label] = ""
|
||||
end
|
||||
|
||||
+14
-5
@@ -75,7 +75,11 @@ function iter_segments(series::Series)
|
||||
if series[:seriestype] in (:scatter, :scatter3d)
|
||||
return [[i] for i in eachindex(y)]
|
||||
else
|
||||
return [i:(i + 1) for i in firstindex(y):lastindex(y)-1]
|
||||
if any(isnan,y)
|
||||
return [iter_segments(y)...]
|
||||
else
|
||||
return [i:(i + 1) for i in firstindex(y):lastindex(y)-1]
|
||||
end
|
||||
end
|
||||
else
|
||||
segs = UnitRange{Int}[]
|
||||
@@ -298,6 +302,11 @@ Base.convert(::Type{Vector{T}}, rng::AbstractRange{S}) where {T<:Real,S<:Real} =
|
||||
|
||||
Base.merge(a::AbstractVector, b::AbstractVector) = sort(unique(vcat(a,b)))
|
||||
|
||||
# recursively merge kw-dicts, e.g. for merging extra_kwargs / extra_plot_kwargs in plotly)
|
||||
recursive_merge(x::AbstractDict...) = merge(recursive_merge, x...)
|
||||
# if values are not AbstractDicts, take the last definition (as does merge)
|
||||
recursive_merge(x...) = x[end]
|
||||
|
||||
nanpush!(a::AbstractVector, b) = (push!(a, NaN); push!(a, b))
|
||||
nanappend!(a::AbstractVector, b) = (push!(a, NaN); append!(a, b))
|
||||
|
||||
@@ -439,12 +448,12 @@ end
|
||||
get_clims(::Series, op=Plots.ignorenan_extrema)
|
||||
|
||||
Finds the limits for the colorbar by taking the "z-values" for the series and passing them into `op`,
|
||||
which must return the tuple `(zmin, zmax)`. The default op is the extrema of the finite
|
||||
which must return the tuple `(zmin, zmax)`. The default op is the extrema of the finite
|
||||
values of the input.
|
||||
"""
|
||||
function get_clims(series::Series, op=ignorenan_extrema)
|
||||
zmin, zmax = Inf, -Inf
|
||||
z_colored_series = (:contour, :contour3d, :heatmap, :histogram2d, :surface)
|
||||
z_colored_series = (:contour, :contour3d, :heatmap, :histogram2d, :surface, :hexbin)
|
||||
for vals in (series[:seriestype] in z_colored_series ? series[:z] : nothing, series[:line_z], series[:marker_z], series[:fill_z])
|
||||
if (typeof(vals) <: AbstractSurface) && (eltype(vals.surf) <: Union{Missing, Real})
|
||||
zmin, zmax = _update_clims(zmin, zmax, op(vals.surf)...)
|
||||
@@ -483,7 +492,7 @@ end
|
||||
hascolorbar(series::Series) = colorbar_style(series) !== nothing
|
||||
hascolorbar(sp::Subplot) = sp[:colorbar] != :none && any(hascolorbar(s) for s in series_list(sp))
|
||||
|
||||
iscontour(series::Series) = series[:seriestype] == :contour
|
||||
iscontour(series::Series) = series[:seriestype] in (:contour, :contour3d)
|
||||
isfilledcontour(series::Series) = iscontour(series) && series[:fillrange] !== nothing
|
||||
|
||||
function contour_levels(series::Series, clims)
|
||||
@@ -979,7 +988,7 @@ px2inch(px::Real) = float(px / PX_PER_INCH)
|
||||
inch2mm(inches::Real) = float(inches * MM_PER_INCH)
|
||||
mm2inch(mm::Real) = float(mm / MM_PER_INCH)
|
||||
px2mm(px::Real) = float(px * MM_PER_PX)
|
||||
mm2px(mm::Real) = float(px / MM_PER_PX)
|
||||
mm2px(mm::Real) = float(mm / MM_PER_PX)
|
||||
|
||||
|
||||
"Smallest x in plot"
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user