format file
This commit is contained in:
parent
d5788fc1e7
commit
d08422811e
@ -51,7 +51,7 @@ function pgfx_preamble(pgfx_plot::Plot{PGFPlotsXBackend})
|
||||
old_flag = pgfx_plot.attr[:tex_output_standalone]
|
||||
pgfx_plot.attr[:tex_output_standalone] = true
|
||||
fulltext = String(repr("application/x-tex", pgfx_plot))
|
||||
preamble = fulltext[1:first(findfirst("\\begin{document}", fulltext))-1]
|
||||
preamble = fulltext[1:(first(findfirst("\\begin{document}", fulltext)) - 1)]
|
||||
pgfx_plot.attr[:tex_output_standalone] = old_flag
|
||||
preamble
|
||||
end
|
||||
@ -129,7 +129,8 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
||||
) => nothing,
|
||||
"fill" => cstr,
|
||||
"fill opacity" => a,
|
||||
"text opacity" => alpha(plot_color(sp[:legendfontcolor])),
|
||||
"text opacity" =>
|
||||
alpha(plot_color(sp[:legendfontcolor])),
|
||||
"font" => pgfx_font(
|
||||
sp[:legendfontsize],
|
||||
pgfx_thickness_scaling(sp),
|
||||
@ -157,11 +158,8 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
||||
else
|
||||
push!(
|
||||
axis_opt,
|
||||
"legend pos" => get(
|
||||
_pgfplotsx_legend_pos,
|
||||
sp[:legend],
|
||||
"outer north east",
|
||||
),
|
||||
"legend pos" =>
|
||||
get(_pgfplotsx_legend_pos, sp[:legend], "outer north east"),
|
||||
)
|
||||
end
|
||||
for letter in (:x, :y, :z)
|
||||
@ -229,14 +227,15 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
||||
sf = series[:fillrange]
|
||||
series_opt = PGFPlotsX.Options(
|
||||
"color" => single_color(opt[:linecolor]),
|
||||
"name path" => string(series_id)
|
||||
"name path" => string(series_id),
|
||||
)
|
||||
if is3d(series) || st == :heatmap
|
||||
series_func = PGFPlotsX.Plot3
|
||||
else
|
||||
series_func = PGFPlotsX.Plot
|
||||
end
|
||||
if sf !== nothing && !isfilledcontour(series) && series[:ribbon] === nothing
|
||||
if sf !== nothing &&
|
||||
!isfilledcontour(series) && series[:ribbon] === nothing
|
||||
push!(series_opt, "area legend" => nothing)
|
||||
end
|
||||
if st == :heatmap
|
||||
@ -267,7 +266,10 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
||||
scale_factor = 0.025
|
||||
mark_size = opt[:markersize] * scale_factor
|
||||
path = join(
|
||||
["($(x[i] * mark_size), $(y[i] * mark_size))" for i in eachindex(x)],
|
||||
[
|
||||
"($(x[i] * mark_size), $(y[i] * mark_size))"
|
||||
for i in eachindex(x)
|
||||
],
|
||||
" -- ",
|
||||
)
|
||||
c = get_markercolor(series, i)
|
||||
@ -288,9 +290,17 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
||||
segment_opt = merge(segment_opt, pgfx_fillstyle(opt, i))
|
||||
end
|
||||
# add fillrange
|
||||
if sf !== nothing && !isfilledcontour(series) && series[:ribbon] === nothing
|
||||
if sf !== nothing &&
|
||||
!isfilledcontour(series) && series[:ribbon] === nothing
|
||||
if sf isa Number || sf isa AVec
|
||||
pgfx_fillrange_series!( axis, series, series_func, i, _cycle(sf, rng), rng)
|
||||
pgfx_fillrange_series!(
|
||||
axis,
|
||||
series,
|
||||
series_func,
|
||||
i,
|
||||
_cycle(sf, rng),
|
||||
rng,
|
||||
)
|
||||
end
|
||||
if i == 1 && sp[:legend] != :none && pgfx_should_add_to_legend(series)
|
||||
pgfx_filllegend!(series_opt, opt)
|
||||
@ -298,26 +308,25 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
||||
end
|
||||
# series
|
||||
#
|
||||
coordinates = pgfx_series_coordinates!(
|
||||
sp,
|
||||
series,
|
||||
segment_opt,
|
||||
opt,
|
||||
rng,
|
||||
)
|
||||
segment_plot = series_func(
|
||||
merge(series_opt, segment_opt),
|
||||
coordinates,
|
||||
)
|
||||
coordinates =
|
||||
pgfx_series_coordinates!(sp, series, segment_opt, opt, rng)
|
||||
segment_plot =
|
||||
series_func(merge(series_opt, segment_opt), coordinates)
|
||||
push!(axis, segment_plot)
|
||||
# fill between functions
|
||||
if sf isa Tuple && series[:ribbon] === nothing
|
||||
sf1, sf2 = sf
|
||||
@assert sf1 == series_index "First index of the tuple has to match the current series index."
|
||||
push!(axis, series_func(
|
||||
merge(pgfx_fillstyle(opt, series_index), PGFPlotsX.Options("forget plot" => nothing)),
|
||||
"fill between [of=$series_id and $(_pgfplotsx_series_ids[Symbol(string(sf2))])]"
|
||||
))
|
||||
push!(
|
||||
axis,
|
||||
series_func(
|
||||
merge(
|
||||
pgfx_fillstyle(opt, series_index),
|
||||
PGFPlotsX.Options("forget plot" => nothing),
|
||||
),
|
||||
"fill between [of=$series_id and $(_pgfplotsx_series_ids[Symbol(string(sf2))])]",
|
||||
),
|
||||
)
|
||||
end
|
||||
# add ribbons?
|
||||
ribbon = series[:ribbon]
|
||||
@ -353,7 +362,11 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
||||
end
|
||||
# add subplot annotations
|
||||
for ann in sp[:annotations]
|
||||
pgfx_add_annotation!(axis, locate_annotation(sp, ann...)..., pgfx_thickness_scaling(sp))
|
||||
pgfx_add_annotation!(
|
||||
axis,
|
||||
locate_annotation(sp, ann...)...,
|
||||
pgfx_thickness_scaling(sp),
|
||||
)
|
||||
end
|
||||
end # for series
|
||||
push!(the_plot, axis)
|
||||
@ -496,7 +509,7 @@ function pgfx_series_coordinates!(
|
||||
)
|
||||
push!(
|
||||
segment_opt,
|
||||
"contour prepared" => PGFPlotsX.Options("labels" => opt[:contour_labels],),
|
||||
"contour prepared" => PGFPlotsX.Options("labels" => opt[:contour_labels]),
|
||||
)
|
||||
return PGFPlotsX.Table(Contour.contours(args..., opt[:levels]))
|
||||
end
|
||||
@ -509,7 +522,7 @@ function pgfx_series_coordinates!(
|
||||
xs, ys, zs = collect(args)
|
||||
push!(
|
||||
segment_opt,
|
||||
"contour filled" => PGFPlotsX.Options("labels" => opt[:contour_labels],),
|
||||
"contour filled" => PGFPlotsX.Options("labels" => opt[:contour_labels]),
|
||||
"point meta" => "explicit",
|
||||
"shader" => "flat",
|
||||
)
|
||||
@ -520,10 +533,10 @@ function pgfx_series_coordinates!(
|
||||
end
|
||||
|
||||
cs = join(
|
||||
[join(["($x, $y) [$(zs[j, i])]" for (j, x) in enumerate(xs)], " ") for (
|
||||
i,
|
||||
y,
|
||||
) in enumerate(ys)],
|
||||
[
|
||||
join(["($x, $y) [$(zs[j, i])]" for (j, x) in enumerate(xs)], " ")
|
||||
for (i, y) in enumerate(ys)
|
||||
],
|
||||
"\n\n",
|
||||
)
|
||||
"""
|
||||
@ -576,11 +589,8 @@ const _pgfx_framestyle_defaults = Dict(:semi => :box)
|
||||
|
||||
# we use the anchors to define orientations for example to align left
|
||||
# one needs to use the right edge as anchor
|
||||
const _pgfx_annotation_halign = KW(
|
||||
:center => "",
|
||||
:left => "right",
|
||||
:right => "left",
|
||||
)
|
||||
const _pgfx_annotation_halign =
|
||||
KW(:center => "", :left => "right", :right => "left")
|
||||
## --------------------------------------------------------------------------------------
|
||||
# Generates a colormap for pgfplots based on a ColorGradient
|
||||
pgfx_arrow(::Nothing) = "every arrow/.append style={-}"
|
||||
@ -608,12 +618,9 @@ function pgfx_filllegend!(series_opt, opt)
|
||||
io = IOBuffer()
|
||||
PGFPlotsX.print_tex(io, pgfx_fillstyle(opt))
|
||||
style = strip(String(take!(io)), ['[', ']', ' '])
|
||||
push!(
|
||||
series_opt,
|
||||
"legend image code/.code" => """{
|
||||
push!(series_opt, "legend image code/.code" => """{
|
||||
\\draw[$style] (0cm,-0.1cm) rectangle (0.6cm,0.1cm);
|
||||
}""",
|
||||
)
|
||||
}""")
|
||||
end
|
||||
|
||||
function pgfx_colormap(grad::ColorGradient)
|
||||
@ -632,9 +639,7 @@ function pgfx_framestyle(style::Symbol)
|
||||
return style
|
||||
else
|
||||
default_style = get(_pgfx_framestyle_defaults, style, :axes)
|
||||
@warn(
|
||||
"Framestyle :$style is not (yet) supported by the PGFPlotsX backend. :$default_style was cosen instead.",
|
||||
)
|
||||
@warn( "Framestyle :$style is not (yet) supported by the PGFPlotsX backend. :$default_style was cosen instead.",)
|
||||
default_style
|
||||
end
|
||||
end
|
||||
@ -707,18 +712,21 @@ function pgfx_marker(plotattributes, i = 1)
|
||||
get_markerstrokealpha(plotattributes, i),
|
||||
)
|
||||
a_stroke = alpha(cstr_stroke)
|
||||
mark_size = pgfx_thickness_scaling(plotattributes) * 0.5 *
|
||||
mark_size =
|
||||
pgfx_thickness_scaling(plotattributes) *
|
||||
0.5 *
|
||||
_cycle(plotattributes[:markersize], i)
|
||||
return PGFPlotsX.Options(
|
||||
"mark" => shape isa Shape ? "PlotsShape$i" :
|
||||
get(_pgfplotsx_markers, shape, "*"),
|
||||
"mark" =>
|
||||
shape isa Shape ? "PlotsShape$i" : get(_pgfplotsx_markers, shape, "*"),
|
||||
"mark size" => "$mark_size pt",
|
||||
"mark options" => PGFPlotsX.Options(
|
||||
"color" => cstr_stroke,
|
||||
"draw opacity" => a_stroke,
|
||||
"fill" => cstr,
|
||||
"fill opacity" => a,
|
||||
"line width" => pgfx_thickness_scaling(plotattributes) *
|
||||
"line width" =>
|
||||
pgfx_thickness_scaling(plotattributes) *
|
||||
_cycle(plotattributes[:markerstrokewidth], i),
|
||||
"rotate" => if shape == :dtriangle
|
||||
180
|
||||
@ -874,7 +882,8 @@ function pgfx_axis!(opt::PGFPlotsX.Options, sp::Subplot, letter)
|
||||
opt,
|
||||
string(letter, "label style") => PGFPlotsX.Options(
|
||||
labelpos => nothing,
|
||||
"font" => pgfx_font(axis[:guidefontsize], pgfx_thickness_scaling(sp)),
|
||||
"font" =>
|
||||
pgfx_font(axis[:guidefontsize], pgfx_thickness_scaling(sp)),
|
||||
"color" => cstr,
|
||||
"draw opacity" => α,
|
||||
"rotate" => axis[:guidefontrotation],
|
||||
@ -888,10 +897,8 @@ function pgfx_axis!(opt::PGFPlotsX.Options, sp::Subplot, letter)
|
||||
scale = axis[:scale]
|
||||
if scale in (:log2, :ln, :log10)
|
||||
push!(opt, string(letter, :mode) => "log")
|
||||
scale == :ln || push!(
|
||||
opt,
|
||||
"log basis $letter" => "$(scale == :log2 ? 2 : 10)",
|
||||
)
|
||||
scale == :ln ||
|
||||
push!(opt, "log basis $letter" => "$(scale == :log2 ? 2 : 10)")
|
||||
end
|
||||
|
||||
# ticks on or off
|
||||
@ -914,8 +921,9 @@ function pgfx_axis!(opt::PGFPlotsX.Options, sp::Subplot, letter)
|
||||
if !(axis[:ticks] in (nothing, false, :none, :native)) && framestyle != :none
|
||||
ticks = get_ticks(sp, axis)
|
||||
#pgf plot ignores ticks with angle below 90 when xmin = 90 so shift values
|
||||
tick_values = ispolar(sp) && letter == :x ?
|
||||
[rad2deg.(ticks[1])[3:end]..., 360, 405] : ticks[1]
|
||||
tick_values =
|
||||
ispolar(sp) && letter == :x ? [rad2deg.(ticks[1])[3:end]..., 360, 405] :
|
||||
ticks[1]
|
||||
push!(
|
||||
opt,
|
||||
string(letter, "tick") => string("{", join(tick_values, ","), "}"),
|
||||
@ -931,44 +939,37 @@ function pgfx_axis!(opt::PGFPlotsX.Options, sp::Subplot, letter)
|
||||
end
|
||||
push!(
|
||||
opt,
|
||||
string(letter, "ticklabels") => string(
|
||||
"{\$",
|
||||
join(tick_labels, "\$,\$"),
|
||||
"\$}",
|
||||
),
|
||||
string(letter, "ticklabels") =>
|
||||
string("{\$", join(tick_labels, "\$,\$"), "\$}"),
|
||||
)
|
||||
elseif axis[:showaxis]
|
||||
tick_labels = ispolar(sp) && letter == :x ?
|
||||
[ticks[2][3:end]..., "0", "45"] : ticks[2]
|
||||
tick_labels =
|
||||
ispolar(sp) && letter == :x ? [ticks[2][3:end]..., "0", "45"] :
|
||||
ticks[2]
|
||||
if axis[:formatter] in (:scientific, :auto)
|
||||
tick_labels = string.("\$", convert_sci_unicode.(tick_labels), "\$")
|
||||
tick_labels = replace.(tick_labels, Ref("×" => "\\times"))
|
||||
end
|
||||
push!(
|
||||
opt,
|
||||
string(letter, "ticklabels") => string(
|
||||
"{",
|
||||
join(tick_labels, ","),
|
||||
"}",
|
||||
),
|
||||
string(letter, "ticklabels") =>
|
||||
string("{", join(tick_labels, ","), "}"),
|
||||
)
|
||||
else
|
||||
push!(opt, string(letter, "ticklabels") => "{}")
|
||||
end
|
||||
push!(
|
||||
opt,
|
||||
string(letter, "tick align") => (axis[:tick_direction] == :out ?
|
||||
"outside" : "inside"),
|
||||
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),
|
||||
),
|
||||
"font" =>
|
||||
pgfx_font(axis[:tickfontsize], pgfx_thickness_scaling(sp)),
|
||||
"color" => cstr,
|
||||
"draw opacity" => α,
|
||||
"rotate" => axis[:tickfontrotation],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user