Compare commits

...

8 Commits

Author SHA1 Message Date
Anshul Singhvi 61b5568e5e really fix saving 2020-05-13 18:59:45 +05:30
Anshul Singhvi d337c4edae fix saving 2020-05-13 18:44:12 +05:30
Anshul Singhvi 8db2de64d5 forgot a do 2020-05-13 18:17:19 +05:30
Anshul Singhvi 67a2a0f8d7 Update gr.jl 2020-05-13 14:51:37 +05:30
jamblejoe 238aca6a78 added description for argument legendtitle (#2697) 2020-05-12 18:32:21 +02:00
Simon Christ 1f039b3adc bump version [skip ci] 2020-05-11 16:52:42 +02:00
Simon Christ 219465d599 fix contours (#2692)
* fix 2d-contour

* fix filled contours (colorbar is off)

* activate fixed examples
2020-05-11 16:52:00 +02:00
Simon Christ 1963cee94a fix it again (#2694) 2020-05-11 16:51:38 +02:00
7 changed files with 179 additions and 191 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
name = "Plots"
uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
author = ["Tom Breloff (@tbreloff)"]
version = "1.2.3"
version = "1.2.4"
[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
+1
View File
@@ -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",
+166 -168
View File
@@ -781,161 +781,161 @@ function gr_axis_width(sp, axis)
end
function _update_min_padding!(sp::Subplot{GRBackend})
dpi = sp.plt[:thickness_scaling]
ENV["GKS_ENCODING"] = "utf8"
if !haskey(ENV, "GKSwstype")
if isijulia()
has_user_gkswstype = haskey(ENV, "GKSwstype")
withenv("GKSwstype" => 100, "GKS_ENCODING" => "utf8") do
dpi = sp.plt[:thickness_scaling]
if has_user_gkswstype && isijulia()
ENV["GKSwstype"] = "svg"
end
end
# Add margin given by the user
leftpad = 2mm + sp[:left_margin]
toppad = 2mm + sp[:top_margin]
rightpad = 2mm + sp[:right_margin]
bottompad = 2mm + sp[:bottom_margin]
# Add margin for title
if sp[:title] != ""
gr_set_font(titlefont(sp), sp)
l = last(last(gr_text_size(sp[:title])))
h = 1mm + get_size(sp)[2] * l * px
toppad += h
end
if RecipesPipeline.is3d(sp)
xaxis, yaxis, zaxis = sp[:xaxis], sp[:yaxis], sp[:zaxis]
xticks, yticks, zticks = get_ticks(sp, xaxis), get_ticks(sp, yaxis), get_ticks(sp, zaxis)
# Add margin for x and y ticks
h = 0mm
if !(xticks in (nothing, false, :none))
gr_set_font(
tickfont(xaxis),
halign = (:left, :hcenter, :right)[sign(xaxis[:rotation]) + 2],
valign = (xaxis[:mirror] ? :bottom : :top),
rotation = xaxis[:rotation],
sp
)
l = 0.01 + last(gr_get_ticks_size(xticks, xaxis[:rotation]))
h = max(h, 1mm + get_size(sp)[2] * l * px)
end
if !(yticks in (nothing, false, :none))
gr_set_font(
tickfont(yaxis),
halign = (:left, :hcenter, :right)[sign(yaxis[:rotation]) + 2],
valign = (yaxis[:mirror] ? :bottom : :top),
rotation = yaxis[:rotation],
sp
)
l = 0.01 + last(gr_get_ticks_size(yticks, yaxis[:rotation]))
h = max(h, 1mm + get_size(sp)[2] * l * px)
end
if h > 0mm
if xaxis[:mirror] || yaxis[:mirror]
toppad += h
end
if !xaxis[:mirror] || !yaxis[:mirror]
bottompad += h
end
end
if !(zticks in (nothing, false, :none))
gr_set_font(
tickfont(zaxis),
halign = (zaxis[:mirror] ? :left : :right),
valign = (:top, :vcenter, :bottom)[sign(zaxis[:rotation]) + 2],
rotation = zaxis[:rotation],
color = zaxis[:tickfontcolor],
sp
)
l = 0.01 + first(gr_get_ticks_size(zticks, zaxis[:rotation]))
w = 1mm + get_size(sp)[1] * l * px
if zaxis[:mirror]
rightpad += w
else
leftpad += w
end
end
# Add margin for x or y label
h = 0mm
if xaxis[:guide] != ""
gr_set_font(guidefont(sp[:xaxis]), sp)
l = last(gr_text_size(sp[:xaxis][:guide]))
h = max(h, 1mm + get_size(sp)[2] * l * px)
end
if yaxis[:guide] != ""
gr_set_font(guidefont(sp[:yaxis]), sp)
l = last(gr_text_size(sp[:yaxis][:guide]))
h = max(h, 1mm + get_size(sp)[2] * l * px)
end
if h > 0mm
if xaxis[:guide_position] == :top || (xaxis[:guide_position] == :auto && xaxis[:mirror] == true)
toppad += h
else
bottompad += h
end
end
# Add margin for z label
if zaxis[:guide] != ""
gr_set_font(guidefont(sp[:zaxis]), sp)
l = last(gr_text_size(sp[:zaxis][:guide]))
w = 1mm + get_size(sp)[2] * l * px
if zaxis[:guide_position] == :right || (zaxis[:guide_position] == :auto && zaxis[:mirror] == true)
rightpad += w
else
leftpad += w
end
end
else
# Add margin for x and y ticks
xticks, yticks = get_ticks(sp, sp[:xaxis]), get_ticks(sp, sp[:yaxis])
if !(xticks in (nothing, false, :none))
flip, mirror = gr_set_xticks_font(sp)
l = 0.01 + last(gr_get_ticks_size(xticks, sp[:xaxis][:rotation]))
# Add margin given by the user
leftpad = 2mm + sp[:left_margin]
toppad = 2mm + sp[:top_margin]
rightpad = 2mm + sp[:right_margin]
bottompad = 2mm + sp[:bottom_margin]
# Add margin for title
if sp[:title] != ""
gr_set_font(titlefont(sp), sp)
l = last(last(gr_text_size(sp[:title])))
h = 1mm + get_size(sp)[2] * l * px
if mirror
toppad += h
else
bottompad += h
end
end
if !(yticks in (nothing, false, :none))
flip, mirror = gr_set_yticks_font(sp)
l = 0.01 + first(gr_get_ticks_size(yticks, sp[:yaxis][:rotation]))
w = 1mm + get_size(sp)[1] * l * px
if mirror
rightpad += w
else
leftpad += w
end
toppad += h
end
# Add margin for x label
if sp[:xaxis][:guide] != ""
gr_set_font(guidefont(sp[:xaxis]), sp)
l = last(gr_text_size(sp[:xaxis][:guide]))
h = 1mm + get_size(sp)[2] * l * px
if sp[:xaxis][:guide_position] == :top || (sp[:xaxis][:guide_position] == :auto && sp[:xaxis][:mirror] == true)
toppad += h
else
bottompad += h
if RecipesPipeline.is3d(sp)
xaxis, yaxis, zaxis = sp[:xaxis], sp[:yaxis], sp[:zaxis]
xticks, yticks, zticks = get_ticks(sp, xaxis), get_ticks(sp, yaxis), get_ticks(sp, zaxis)
# Add margin for x and y ticks
h = 0mm
if !(xticks in (nothing, false, :none))
gr_set_font(
tickfont(xaxis),
halign = (:left, :hcenter, :right)[sign(xaxis[:rotation]) + 2],
valign = (xaxis[:mirror] ? :bottom : :top),
rotation = xaxis[:rotation],
sp
)
l = 0.01 + last(gr_get_ticks_size(xticks, xaxis[:rotation]))
h = max(h, 1mm + get_size(sp)[2] * l * px)
end
if !(yticks in (nothing, false, :none))
gr_set_font(
tickfont(yaxis),
halign = (:left, :hcenter, :right)[sign(yaxis[:rotation]) + 2],
valign = (yaxis[:mirror] ? :bottom : :top),
rotation = yaxis[:rotation],
sp
)
l = 0.01 + last(gr_get_ticks_size(yticks, yaxis[:rotation]))
h = max(h, 1mm + get_size(sp)[2] * l * px)
end
if h > 0mm
if xaxis[:mirror] || yaxis[:mirror]
toppad += h
end
if !xaxis[:mirror] || !yaxis[:mirror]
bottompad += h
end
end
if !(zticks in (nothing, false, :none))
gr_set_font(
tickfont(zaxis),
halign = (zaxis[:mirror] ? :left : :right),
valign = (:top, :vcenter, :bottom)[sign(zaxis[:rotation]) + 2],
rotation = zaxis[:rotation],
color = zaxis[:tickfontcolor],
sp
)
l = 0.01 + first(gr_get_ticks_size(zticks, zaxis[:rotation]))
w = 1mm + get_size(sp)[1] * l * px
if zaxis[:mirror]
rightpad += w
else
leftpad += w
end
end
# Add margin for x or y label
h = 0mm
if xaxis[:guide] != ""
gr_set_font(guidefont(sp[:xaxis]), sp)
l = last(gr_text_size(sp[:xaxis][:guide]))
h = max(h, 1mm + get_size(sp)[2] * l * px)
end
if yaxis[:guide] != ""
gr_set_font(guidefont(sp[:yaxis]), sp)
l = last(gr_text_size(sp[:yaxis][:guide]))
h = max(h, 1mm + get_size(sp)[2] * l * px)
end
if h > 0mm
if xaxis[:guide_position] == :top || (xaxis[:guide_position] == :auto && xaxis[:mirror] == true)
toppad += h
else
bottompad += h
end
end
# Add margin for z label
if zaxis[:guide] != ""
gr_set_font(guidefont(sp[:zaxis]), sp)
l = last(gr_text_size(sp[:zaxis][:guide]))
w = 1mm + get_size(sp)[2] * l * px
if zaxis[:guide_position] == :right || (zaxis[:guide_position] == :auto && zaxis[:mirror] == true)
rightpad += w
else
leftpad += w
end
end
else
# Add margin for x and y ticks
xticks, yticks = get_ticks(sp, sp[:xaxis]), get_ticks(sp, sp[:yaxis])
if !(xticks in (nothing, false, :none))
flip, mirror = gr_set_xticks_font(sp)
l = 0.01 + last(gr_get_ticks_size(xticks, sp[:xaxis][:rotation]))
h = 1mm + get_size(sp)[2] * l * px
if mirror
toppad += h
else
bottompad += h
end
end
if !(yticks in (nothing, false, :none))
flip, mirror = gr_set_yticks_font(sp)
l = 0.01 + first(gr_get_ticks_size(yticks, sp[:yaxis][:rotation]))
w = 1mm + get_size(sp)[1] * l * px
if mirror
rightpad += w
else
leftpad += w
end
end
# Add margin for x label
if sp[:xaxis][:guide] != ""
gr_set_font(guidefont(sp[:xaxis]), sp)
l = last(gr_text_size(sp[:xaxis][:guide]))
h = 1mm + get_size(sp)[2] * l * px
if sp[:xaxis][:guide_position] == :top || (sp[:xaxis][:guide_position] == :auto && sp[:xaxis][:mirror] == true)
toppad += h
else
bottompad += h
end
end
# Add margin for y label
if sp[:yaxis][:guide] != ""
gr_set_font(guidefont(sp[:yaxis]), sp)
l = last(gr_text_size(sp[:yaxis][:guide]))
w = 1mm + get_size(sp)[2] * l * px
if sp[:yaxis][:guide_position] == :right || (sp[:yaxis][:guide_position] == :auto && sp[:yaxis][:mirror] == true)
rightpad += w
else
leftpad += w
end
end
end
# Add margin for y label
if sp[:yaxis][:guide] != ""
gr_set_font(guidefont(sp[:yaxis]), sp)
l = last(gr_text_size(sp[:yaxis][:guide]))
w = 1mm + get_size(sp)[2] * l * px
if sp[:yaxis][:guide_position] == :right || (sp[:yaxis][:guide_position] == :auto && sp[:yaxis][:mirror] == true)
rightpad += w
else
leftpad += w
end
if sp[:colorbar_title] != ""
rightpad += 4mm
end
end
if sp[:colorbar_title] != ""
rightpad += 4mm
end
sp.minpad = Tuple(dpi * [leftpad, toppad, rightpad, bottompad])
sp.minpad = Tuple(dpi * [leftpad, toppad, rightpad, bottompad])
end # end withenv
end
function is_equally_spaced(v)
@@ -1938,20 +1938,17 @@ for (mime, fmt) in (
"image/svg+xml" => "svg",
)
@eval function _show(io::IO, ::MIME{Symbol($mime)}, plt::Plot{GRBackend})
ENV["GKS_ENCODING"] = "utf8"
GR.emergencyclosegks()
filepath = tempname() * "." * $fmt
env = get(ENV, "GKSwstype", "0")
ENV["GKSwstype"] = $fmt
ENV["GKS_FILEPATH"] = filepath
gr_display(plt, $fmt)
GR.emergencyclosegks()
write(io, read(filepath, String))
rm(filepath)
if env != "0"
ENV["GKSwstype"] = env
else
pop!(ENV, "GKSwstype")
withenv(
"GKS_ENCODING" => "utf8",
"GKSwstype" => $fmt,
"GKS_FILEPATH" => filepath
) do
gr_display(plt, $fmt)
GR.emergencyclosegks()
write(io, read(filepath, String))
rm(filepath)
end
end
end
@@ -1961,16 +1958,17 @@ function _display(plt::Plot{GRBackend})
if plt[:display_type] == :inline
GR.emergencyclosegks()
filepath = tempname() * ".pdf"
ENV["GKSwstype"] = "pdf"
ENV["GKS_FILEPATH"] = filepath
gr_display(plt)
GR.emergencyclosegks()
content = string("\033]1337;File=inline=1;preserveAspectRatio=0:", base64encode(open(read, filepath)), "\a")
println(content)
rm(filepath)
withenv("GKSwstype" => "pdf", "GKS_FILEPATH" => filepath) do
gr_display(plt)
GR.emergencyclosegks()
content = string("\033]1337;File=inline=1;preserveAspectRatio=0:", base64encode(open(read, filepath)), "\a")
println(content)
rm(filepath)
end
else
ENV["GKS_DOUBLE_BUF"] = true
gr_display(plt)
withenv("GKS_DOUBLE_BUF" => true) do
gr_display(plt)
end
end
end
+8 -17
View File
@@ -288,7 +288,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 +297,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 +342,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 +597,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 +607,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(
-2
View File
@@ -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
],
)
+2 -2
View File
@@ -160,9 +160,9 @@ end
function RecipesPipeline.process_sliced_series_attributes!(plt::Plots.Plot, kw_list)
# swap errors
err_inds = findall(kw -> get(kw, :seriestype, nothing) in (:xerror, :yerror, :zerror), kw_list)
err_inds = findall(kw -> get(kw, :seriestype, :path) in (:xerror, :yerror, :zerror), kw_list)
for ind in err_inds
if kw_list[ind-1][:seriestype] == :scatter
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
+1 -1
View File
@@ -487,7 +487,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)