Merge pull request #1610 from daschw/pyplot-thickness

fix pyplot thickness_scaling (fix #1606)
This commit is contained in:
Daniel Schwabeneder 2018-07-28 08:53:03 +02:00 committed by GitHub
commit da765a5eec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 33 deletions

View File

@ -12,6 +12,9 @@
## (current master) ## (current master)
- All new development should target Julia 0.7! - All new development should target Julia 0.7!
## 0.17.4
- fix thickness_scaling for pyplot
## 0.17.3 ## 0.17.3
- Log-scale heatmap edge computation - Log-scale heatmap edge computation
- Fix size and dpi for GR and PyPlot - Fix size and dpi for GR and PyPlot

View File

@ -394,8 +394,8 @@ function py_bbox_title(ax)
bb bb
end end
function py_dpi_scale(plt::Plot{PyPlotBackend}, ptsz) function py_thickness_scale(plt::Plot{PyPlotBackend}, ptsz)
ptsz ptsz * plt[:thickness_scaling]
end end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
@ -505,7 +505,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
# :label => series[:label], # :label => series[:label],
# :zorder => plt.n, # :zorder => plt.n,
# :cmap => py_linecolormap(series), # :cmap => py_linecolormap(series),
# :linewidths => py_dpi_scale(plt, get_linewidth.(series, 1:n)), # :linewidths => py_thickness_scale(plt, get_linewidth.(series, 1:n)),
# :linestyle => py_linestyle(st, get_linestyle.(series)), # :linestyle => py_linestyle(st, get_linestyle.(series)),
# :norm => pycolors["Normalize"](; extrakw...) # :norm => pycolors["Normalize"](; extrakw...)
# ) # )
@ -530,7 +530,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
label = i == 1 ? series[:label] : "", label = i == 1 ? series[:label] : "",
zorder = series[:series_plotindex], zorder = series[:series_plotindex],
color = py_color(get_linecolor(series, i), get_linealpha(series, i)), color = py_color(get_linecolor(series, i), get_linealpha(series, i)),
linewidth = py_dpi_scale(plt, get_linewidth(series, i)), linewidth = py_thickness_scale(plt, get_linewidth(series, i)),
linestyle = py_linestyle(st, get_linestyle(series, i)), linestyle = py_linestyle(st, get_linestyle(series, i)),
solid_capstyle = "round", solid_capstyle = "round",
drawstyle = py_stepstyle(st) drawstyle = py_stepstyle(st)
@ -550,7 +550,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
:shrinkB => 0, :shrinkB => 0,
:edgecolor => py_linecolor(series), :edgecolor => py_linecolor(series),
:facecolor => py_linecolor(series), :facecolor => py_linecolor(series),
:linewidth => py_dpi_scale(plt, get_linewidth(series)), :linewidth => py_thickness_scale(plt, get_linewidth(series)),
:linestyle => py_linestyle(st, get_linestyle(series)), :linestyle => py_linestyle(st, get_linestyle(series)),
) )
add_arrows(x, y) do xyprev, xy add_arrows(x, y) do xyprev, xy
@ -589,7 +589,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
x,y = xyargs x,y = xyargs
shapes = series[:markershape] shapes = series[:markershape]
msc = py_markerstrokecolor(series) msc = py_markerstrokecolor(series)
lw = py_dpi_scale(plt, series[:markerstrokewidth]) lw = py_thickness_scale(plt, series[:markerstrokewidth])
for i=1:length(y) for i=1:length(y)
extrakw[:c] = _cycle(markercolor, i) extrakw[:c] = _cycle(markercolor, i)
@ -597,7 +597,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
label = series[:label], label = series[:label],
zorder = series[:series_plotindex] + 0.5, zorder = series[:series_plotindex] + 0.5,
marker = py_marker(_cycle(shapes,i)), marker = py_marker(_cycle(shapes,i)),
s = py_dpi_scale(plt, _cycle(series[:markersize],i) .^ 2), s = py_thickness_scale(plt, _cycle(series[:markersize],i) .^ 2),
edgecolors = msc, edgecolors = msc,
linewidths = lw, linewidths = lw,
extrakw... extrakw...
@ -610,9 +610,9 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
label = series[:label], label = series[:label],
zorder = series[:series_plotindex] + 0.5, zorder = series[:series_plotindex] + 0.5,
marker = py_marker(series[:markershape]), marker = py_marker(series[:markershape]),
s = py_dpi_scale(plt, series[:markersize] .^ 2), s = py_thickness_scale(plt, series[:markersize] .^ 2),
edgecolors = py_markerstrokecolor(series), edgecolors = py_markerstrokecolor(series),
linewidths = py_dpi_scale(plt, series[:markerstrokewidth]), linewidths = py_thickness_scale(plt, series[:markerstrokewidth]),
extrakw... extrakw...
) )
push!(handles, handle) push!(handles, handle)
@ -624,7 +624,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
label = series[:label], label = series[:label],
zorder = series[:series_plotindex], zorder = series[:series_plotindex],
gridsize = series[:bins], gridsize = series[:bins],
linewidths = py_dpi_scale(plt, series[:linewidth]), linewidths = py_thickness_scale(plt, series[:linewidth]),
edgecolors = py_linecolor(series), edgecolors = py_linecolor(series),
cmap = py_fillcolormap(series), # applies to the pcolorfast object cmap = py_fillcolormap(series), # applies to the pcolorfast object
extrakw... extrakw...
@ -655,7 +655,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
handle = ax[:contour](x, y, z, levelargs...; handle = ax[:contour](x, y, z, levelargs...;
label = series[:label], label = series[:label],
zorder = series[:series_plotindex], zorder = series[:series_plotindex],
linewidths = py_dpi_scale(plt, series[:linewidth]), linewidths = py_thickness_scale(plt, series[:linewidth]),
linestyles = py_linestyle(st, series[:linestyle]), linestyles = py_linestyle(st, series[:linestyle]),
extrakw... extrakw...
) )
@ -697,7 +697,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
zorder = series[:series_plotindex], zorder = series[:series_plotindex],
rstride = series[:stride][1], rstride = series[:stride][1],
cstride = series[:stride][2], cstride = series[:stride][2],
linewidth = py_dpi_scale(plt, series[:linewidth]), linewidth = py_thickness_scale(plt, series[:linewidth]),
edgecolor = py_linecolor(series), edgecolor = py_linecolor(series),
extrakw... extrakw...
) )
@ -728,7 +728,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
label = series[:label], label = series[:label],
zorder = series[:series_plotindex], zorder = series[:series_plotindex],
cmap = py_fillcolormap(series), cmap = py_fillcolormap(series),
linewidth = py_dpi_scale(plt, series[:linewidth]), linewidth = py_thickness_scale(plt, series[:linewidth]),
edgecolor = py_linecolor(series), edgecolor = py_linecolor(series),
extrakw... extrakw...
) )
@ -796,7 +796,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
zorder = series[:series_plotindex], zorder = series[:series_plotindex],
edgecolor = py_color(get_linecolor(series, i), get_linealpha(series, i)), edgecolor = py_color(get_linecolor(series, i), get_linealpha(series, i)),
facecolor = py_color(get_fillcolor(series, i), get_fillalpha(series, i)), facecolor = py_color(get_fillcolor(series, i), get_fillalpha(series, i)),
linewidth = py_dpi_scale(plt, get_linewidth(series, i)), linewidth = py_thickness_scale(plt, get_linewidth(series, i)),
linestyle = py_linestyle(st, get_linestyle(series, i)), linestyle = py_linestyle(st, get_linestyle(series, i)),
fill = true fill = true
) )
@ -955,8 +955,8 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
w, h = plt[:size] w, h = plt[:size]
fig = plt.o fig = plt.o
fig[:clear]() fig[:clear]()
dpi = plt[:thickness_scaling] * plt[:dpi] dpi = plt[:dpi]
fig[:set_size_inches](w/DPI/plt[:thickness_scaling], h/DPI/plt[:thickness_scaling], forward = true) fig[:set_size_inches](w/DPI, h/DPI, forward = true)
fig[set_facecolor_sym](py_color(plt[:background_color_outside])) fig[set_facecolor_sym](py_color(plt[:background_color_outside]))
fig[:set_dpi](plt[:dpi]) fig[:set_dpi](plt[:dpi])
@ -996,7 +996,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
:title :title
end end
ax[func][:set_text](sp[:title]) ax[func][:set_text](sp[:title])
ax[func][:set_fontsize](py_dpi_scale(plt, sp[:titlefontsize])) ax[func][:set_fontsize](py_thickness_scale(plt, sp[:titlefontsize]))
ax[func][:set_family](sp[:titlefontfamily]) ax[func][:set_family](sp[:titlefontfamily])
ax[func][:set_color](py_color(sp[:titlefontcolor])) ax[func][:set_color](py_color(sp[:titlefontcolor]))
# ax[:set_title](sp[:title], loc = loc) # ax[:set_title](sp[:title], loc = loc)
@ -1036,9 +1036,9 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
fig = plt.o fig = plt.o
cbax = fig[:add_axes]([0.8,0.1,0.03,0.8], label = string(gensym())) cbax = fig[:add_axes]([0.8,0.1,0.03,0.8], label = string(gensym()))
cb = fig[:colorbar](handle; cax = cbax, kw...) cb = fig[:colorbar](handle; cax = cbax, kw...)
cb[:set_label](sp[:colorbar_title],size=py_dpi_scale(plt, sp[:yaxis][:guidefontsize]),family=sp[:yaxis][:guidefontfamily], color = py_color(sp[:yaxis][:guidefontcolor])) cb[:set_label](sp[:colorbar_title],size=py_thickness_scale(plt, sp[:yaxis][:guidefontsize]),family=sp[:yaxis][:guidefontfamily], color = py_color(sp[:yaxis][:guidefontcolor]))
for lab in cb[:ax][:yaxis][:get_ticklabels]() for lab in cb[:ax][:yaxis][:get_ticklabels]()
lab[:set_fontsize](py_dpi_scale(plt, sp[:yaxis][:tickfontsize])) lab[:set_fontsize](py_thickness_scale(plt, sp[:yaxis][:tickfontsize]))
lab[:set_family](sp[:yaxis][:tickfontfamily]) lab[:set_family](sp[:yaxis][:tickfontfamily])
lab[:set_color](py_color(sp[:yaxis][:tickfontcolor])) lab[:set_color](py_color(sp[:yaxis][:tickfontcolor]))
end end
@ -1048,12 +1048,14 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
# framestyle # framestyle
if !ispolar(sp) && !is3d(sp) if !ispolar(sp) && !is3d(sp)
ax[:spines]["left"][:set_linewidth](py_thickness_scale(plt, 1))
ax[:spines]["bottom"][:set_linewidth](py_thickness_scale(plt, 1))
if sp[:framestyle] == :semi if sp[:framestyle] == :semi
intensity = 0.5 intensity = 0.5
ax[:spines]["right"][:set_alpha](intensity) ax[:spines]["right"][:set_alpha](intensity)
ax[:spines]["top"][:set_alpha](intensity) ax[:spines]["top"][:set_alpha](intensity)
ax[:spines]["right"][:set_linewidth](intensity) ax[:spines]["right"][:set_linewidth](py_thickness_scale(plt, intensity))
ax[:spines]["top"][:set_linewidth](intensity) ax[:spines]["top"][:set_linewidth](py_thickness_scale(plt, intensity))
elseif sp[:framestyle] in (:axes, :origin) elseif sp[:framestyle] in (:axes, :origin)
ax[:spines]["right"][:set_visible](false) ax[:spines]["right"][:set_visible](false)
ax[:spines]["top"][:set_visible](false) ax[:spines]["top"][:set_visible](false)
@ -1066,8 +1068,8 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
spine[:set_visible](false) spine[:set_visible](false)
end end
if sp[:framestyle] == :zerolines if sp[:framestyle] == :zerolines
ax[:axhline](y = 0, color = py_color(sp[:xaxis][:foreground_color_axis]), lw = 0.75) ax[:axhline](y = 0, color = py_color(sp[:xaxis][:foreground_color_axis]), lw = py_thickness_scale(plt, 0.75))
ax[:axvline](x = 0, color = py_color(sp[:yaxis][:foreground_color_axis]), lw = 0.75) ax[:axvline](x = 0, color = py_color(sp[:yaxis][:foreground_color_axis]), lw = py_thickness_scale(plt, 0.75))
end end
end end
end end
@ -1100,10 +1102,10 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
if get(axis.d, :flip, false) if get(axis.d, :flip, false)
ax[Symbol("invert_", letter, "axis")]() ax[Symbol("invert_", letter, "axis")]()
end end
pyaxis[:label][:set_fontsize](py_dpi_scale(plt, axis[:guidefontsize])) pyaxis[:label][:set_fontsize](py_thickness_scale(plt, axis[:guidefontsize]))
pyaxis[:label][:set_family](axis[:guidefontfamily]) pyaxis[:label][:set_family](axis[:guidefontfamily])
for lab in ax[Symbol("get_", letter, "ticklabels")]() for lab in ax[Symbol("get_", letter, "ticklabels")]()
lab[:set_fontsize](py_dpi_scale(plt, axis[:tickfontsize])) lab[:set_fontsize](py_thickness_scale(plt, axis[:tickfontsize]))
lab[:set_family](axis[:tickfontfamily]) lab[:set_family](axis[:tickfontfamily])
lab[:set_rotation](axis[:rotation]) lab[:set_rotation](axis[:rotation])
end end
@ -1112,7 +1114,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
pyaxis[:grid](true, pyaxis[:grid](true,
color = fgcolor, color = fgcolor,
linestyle = py_linestyle(:line, axis[:gridstyle]), linestyle = py_linestyle(:line, axis[:gridstyle]),
linewidth = axis[:gridlinewidth], linewidth = py_thickness_scale(plt, axis[:gridlinewidth]),
alpha = axis[:gridalpha]) alpha = axis[:gridalpha])
ax[:set_axisbelow](true) ax[:set_axisbelow](true)
else else
@ -1209,7 +1211,7 @@ function _update_min_padding!(sp::Subplot{PyPlotBackend})
rightpad += sp[:right_margin] rightpad += sp[:right_margin]
bottompad += sp[:bottom_margin] bottompad += sp[:bottom_margin]
dpi_factor = sp.plt[:thickness_scaling] * Plots.DPI / sp.plt[:dpi] dpi_factor = Plots.DPI / sp.plt[:dpi]
sp.minpad = Tuple(dpi_factor .* [leftpad, toppad, rightpad, bottompad]) sp.minpad = Tuple(dpi_factor .* [leftpad, toppad, rightpad, bottompad])
end end
@ -1232,7 +1234,7 @@ function py_add_annotations(sp::Subplot{PyPlotBackend}, x, y, val::PlotText)
horizontalalignment = val.font.halign == :hcenter ? "center" : string(val.font.halign), horizontalalignment = val.font.halign == :hcenter ? "center" : string(val.font.halign),
verticalalignment = val.font.valign == :vcenter ? "center" : string(val.font.valign), verticalalignment = val.font.valign == :vcenter ? "center" : string(val.font.valign),
rotation = val.font.rotation * 180 / π, rotation = val.font.rotation * 180 / π,
size = py_dpi_scale(sp.plt, val.font.pointsize), size = py_thickness_scale(sp.plt, val.font.pointsize),
zorder = 999 zorder = 999
) )
end end
@ -1263,13 +1265,13 @@ function py_add_legend(plt::Plot, sp::Subplot, ax)
pypatches[:Patch]( pypatches[:Patch](
edgecolor = py_color(get_linecolor(series), get_linealpha(series)), edgecolor = py_color(get_linecolor(series), get_linealpha(series)),
facecolor = py_color(get_fillcolor(series), get_fillalpha(series)), facecolor = py_color(get_fillcolor(series), get_fillalpha(series)),
linewidth = py_dpi_scale(plt, clamp(get_linewidth(series), 0, 5)), linewidth = py_thickness_scale(plt, clamp(get_linewidth(series), 0, 5)),
linestyle = py_linestyle(series[:seriestype], get_linestyle(series)) linestyle = py_linestyle(series[:seriestype], get_linestyle(series))
) )
elseif series[:seriestype] in (:path, :straightline) elseif series[:seriestype] in (:path, :straightline)
PyPlot.plt[:Line2D]((0,1),(0,0), PyPlot.plt[:Line2D]((0,1),(0,0),
color = py_color(get_linecolor(series), get_linealpha(series)), color = py_color(get_linecolor(series), get_linealpha(series)),
linewidth = py_dpi_scale(plt, clamp(get_linewidth(series), 0, 5)), linewidth = py_thickness_scale(plt, clamp(get_linewidth(series), 0, 5)),
linestyle = py_linestyle(:path, get_linestyle(series)), linestyle = py_linestyle(:path, get_linestyle(series)),
marker = py_marker(series[:markershape]), marker = py_marker(series[:markershape]),
markeredgecolor = py_color(get_markerstrokecolor(series), get_markerstrokealpha(series)), markeredgecolor = py_color(get_markerstrokecolor(series), get_markerstrokealpha(series)),
@ -1288,11 +1290,13 @@ function py_add_legend(plt::Plot, sp::Subplot, ax)
labels, labels,
loc = get(_pyplot_legend_pos, leg, "best"), loc = get(_pyplot_legend_pos, leg, "best"),
scatterpoints = 1, scatterpoints = 1,
fontsize = py_dpi_scale(plt, sp[:legendfontsize]), fontsize = py_thickness_scale(plt, sp[:legendfontsize]),
facecolor = py_color(sp[:background_color_legend]), facecolor = py_color(sp[:background_color_legend]),
edgecolor = py_color(sp[:foreground_color_legend]), edgecolor = py_color(sp[:foreground_color_legend]),
framealpha = alpha(plot_color(sp[:background_color_legend])), framealpha = alpha(plot_color(sp[:background_color_legend])),
) )
frame = leg[:get_frame]()
frame[:set_linewidth](py_thickness_scale(plt, 1))
leg[:set_zorder](1000) leg[:set_zorder](1000)
sp[:legendtitle] != nothing && leg[:set_title](sp[:legendtitle]) sp[:legendtitle] != nothing && leg[:set_title](sp[:legendtitle])
@ -1360,7 +1364,7 @@ for (mime, fmt) in _pyplot_mimeformats
# figsize = map(px2inch, plt[:size]), # figsize = map(px2inch, plt[:size]),
facecolor = fig[:get_facecolor](), facecolor = fig[:get_facecolor](),
edgecolor = "none", edgecolor = "none",
dpi = plt[:dpi] * plt[:thickness_scaling] dpi = plt[:dpi]
) )
end end
end end

View File

@ -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 # 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) # is referenced in a button press callback (the button clicked callback will call notify() on that condition)
const _current_plots_version = v"0.17.3" const _current_plots_version = v"0.17.4"
function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = isinteractive(), sigma = [1,1], eps = 1e-2) function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = isinteractive(), sigma = [1,1], eps = 1e-2)