Fix small issues with response to :dpi value.

This commit is contained in:
MA Laforge 2017-03-18 20:59:39 -04:00
parent 8e6fdfac3c
commit cb278b053d
3 changed files with 23 additions and 18 deletions

View File

@ -232,7 +232,7 @@ const _plot_defaults = KW(
:html_output_format => :auto,
:inset_subplots => nothing, # optionally pass a vector of (parent,bbox) tuples which are
# the parent layout and the relative bounding box of inset subplots
:dpi => DPI, # dots per inch for images, etc
:dpi => DEFAULT_DPI, # dots per inch for images, etc
:display_type => :auto,
:extra_kwargs => KW(),
)

View File

@ -370,15 +370,19 @@ function py_bbox_title(ax)
bb
end
function py_dpi_scale(plt::Plot{PyPlotBackend}, ptsz)
ptsz * plt[:dpi] / DPI
end
#Re-scale font size (points) before sending to PyPlot:
py_font_scale(plt::Plot{PyPlotBackend}, ptsz) = Float64(ptsz) #Passthrough
#Convert pixels to PyPlot's unit (typography points):
py_dpi_scale(plt::Plot{PyPlotBackend}, px) = px2pt(px, plt[:dpi])
py_dpi_scale(plt::Plot{PyPlotBackend}, v::Vector) = Float64[py_dpi_scale(plt,px) for px in v]
# ---------------------------------------------------------------------------
# Create the window/figure for this backend.
function _create_backend_figure(plt::Plot{PyPlotBackend})
w,h = map(px2inch, plt[:size])
# dpi = plt[:dpi]
# w,h = map((px)->px2inch(px,dpi), plt[:size])
# # reuse the current figure?
fig = if plt[:overwrite_figure]
@ -984,7 +988,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
fig = plt.o
fig[:clear]()
dpi = plt[:dpi]
fig[:set_size_inches](w/dpi, h/dpi, forward = true)
fig[:set_size_inches](px2inch(w, dpi), px2inch(h, dpi), forward = true)
fig[:set_facecolor](py_color(plt[:background_color_outside]))
fig[:set_dpi](dpi)
@ -1024,7 +1028,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
:title
end
ax[func][:set_text](sp[:title])
ax[func][:set_fontsize](py_dpi_scale(plt, sp[:titlefont].pointsize))
ax[func][:set_fontsize](py_font_scale(plt, sp[:titlefont].pointsize))
ax[func][:set_family](sp[:titlefont].family)
ax[func][:set_color](py_color(sp[:foreground_color_title]))
# ax[:set_title](sp[:title], loc = loc)
@ -1049,10 +1053,10 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
if get(axis.d, :flip, false)
ax[Symbol("invert_", letter, "axis")]()
end
pyaxis[:label][:set_fontsize](py_dpi_scale(plt, axis[:guidefont].pointsize))
pyaxis[:label][:set_fontsize](py_font_scale(plt, axis[:guidefont].pointsize))
pyaxis[:label][:set_family](axis[:guidefont].family)
for lab in ax[Symbol("get_", letter, "ticklabels")]()
lab[:set_fontsize](py_dpi_scale(plt, axis[:tickfont].pointsize))
lab[:set_fontsize](py_font_scale(plt, axis[:tickfont].pointsize))
lab[:set_family](axis[:tickfont].family)
lab[:set_rotation](axis[:rotation])
end
@ -1137,7 +1141,7 @@ function py_add_annotations(sp::Subplot{PyPlotBackend}, x, y, val::PlotText)
horizontalalignment = val.font.halign == :hcenter ? "center" : string(val.font.halign),
verticalalignment = val.font.valign == :vcenter ? "center" : string(val.font.valign),
rotation = val.font.rotation * 180 / π,
size = py_dpi_scale(sp.plt, val.font.pointsize),
size = py_font_scale(sp.plt, val.font.pointsize),
zorder = 999
)
end
@ -1182,7 +1186,7 @@ function py_add_legend(plt::Plot, sp::Subplot, ax)
labels,
loc = get(_pyplot_legend_pos, leg, "best"),
scatterpoints = 1,
fontsize = py_dpi_scale(plt, sp[:legendfont].pointsize)
fontsize = py_font_scale(plt, sp[:legendfont].pointsize)
# family = sp[:legendfont].family
# framealpha = 0.6
)

View File

@ -857,17 +857,18 @@ end
# Some conversion functions
# note: I borrowed these conversion constants from Compose.jl's Measure
const PX_PER_INCH = 100
const DPI = PX_PER_INCH
const DTPPOINTS_PER_INCH = 72 #Typography (desktop publishing) points per inch
const DEFAULT_DPI = DTPPOINTS_PER_INCH
const MM_PER_INCH = 25.4
const MM_PER_PX = MM_PER_INCH / PX_PER_INCH
inch2px(inches::Real) = float(inches * PX_PER_INCH)
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)
px2inch(px::Float64, dpi::Float64) = px / dpi
px2inch(px::Real, dpi::Real) = px2inch(Float64(px), Float64(dpi))
#Convert to typography "points":
px2pt(px::Float64, dpi::Float64) = px * (DTPPOINTS_PER_INCH / dpi)
px2pt(px::Real, dpi::Real) = px2pt(Float64(px), Float64(dpi))
"Smallest x in plot"