Fix small issues with response to :dpi value.
This commit is contained in:
parent
8e6fdfac3c
commit
cb278b053d
@ -232,7 +232,7 @@ const _plot_defaults = KW(
|
|||||||
:html_output_format => :auto,
|
:html_output_format => :auto,
|
||||||
:inset_subplots => nothing, # optionally pass a vector of (parent,bbox) tuples which are
|
:inset_subplots => nothing, # optionally pass a vector of (parent,bbox) tuples which are
|
||||||
# the parent layout and the relative bounding box of inset subplots
|
# 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,
|
:display_type => :auto,
|
||||||
:extra_kwargs => KW(),
|
:extra_kwargs => KW(),
|
||||||
)
|
)
|
||||||
|
|||||||
@ -370,15 +370,19 @@ function py_bbox_title(ax)
|
|||||||
bb
|
bb
|
||||||
end
|
end
|
||||||
|
|
||||||
function py_dpi_scale(plt::Plot{PyPlotBackend}, ptsz)
|
#Re-scale font size (points) before sending to PyPlot:
|
||||||
ptsz * plt[:dpi] / DPI
|
py_font_scale(plt::Plot{PyPlotBackend}, ptsz) = Float64(ptsz) #Passthrough
|
||||||
end
|
|
||||||
|
#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.
|
# Create the window/figure for this backend.
|
||||||
function _create_backend_figure(plt::Plot{PyPlotBackend})
|
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?
|
# # reuse the current figure?
|
||||||
fig = if plt[:overwrite_figure]
|
fig = if plt[:overwrite_figure]
|
||||||
@ -984,7 +988,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
|
|||||||
fig = plt.o
|
fig = plt.o
|
||||||
fig[:clear]()
|
fig[:clear]()
|
||||||
dpi = plt[:dpi]
|
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_facecolor](py_color(plt[:background_color_outside]))
|
||||||
fig[:set_dpi](dpi)
|
fig[:set_dpi](dpi)
|
||||||
|
|
||||||
@ -1024,7 +1028,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[:titlefont].pointsize))
|
ax[func][:set_fontsize](py_font_scale(plt, sp[:titlefont].pointsize))
|
||||||
ax[func][:set_family](sp[:titlefont].family)
|
ax[func][:set_family](sp[:titlefont].family)
|
||||||
ax[func][:set_color](py_color(sp[:foreground_color_title]))
|
ax[func][:set_color](py_color(sp[:foreground_color_title]))
|
||||||
# ax[:set_title](sp[:title], loc = loc)
|
# ax[:set_title](sp[:title], loc = loc)
|
||||||
@ -1049,10 +1053,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[:guidefont].pointsize))
|
pyaxis[:label][:set_fontsize](py_font_scale(plt, axis[:guidefont].pointsize))
|
||||||
pyaxis[:label][:set_family](axis[:guidefont].family)
|
pyaxis[:label][:set_family](axis[:guidefont].family)
|
||||||
for lab in ax[Symbol("get_", letter, "ticklabels")]()
|
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_family](axis[:tickfont].family)
|
||||||
lab[:set_rotation](axis[:rotation])
|
lab[:set_rotation](axis[:rotation])
|
||||||
end
|
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),
|
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_font_scale(sp.plt, val.font.pointsize),
|
||||||
zorder = 999
|
zorder = 999
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@ -1182,7 +1186,7 @@ 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[:legendfont].pointsize)
|
fontsize = py_font_scale(plt, sp[:legendfont].pointsize)
|
||||||
# family = sp[:legendfont].family
|
# family = sp[:legendfont].family
|
||||||
# framealpha = 0.6
|
# framealpha = 0.6
|
||||||
)
|
)
|
||||||
|
|||||||
15
src/utils.jl
15
src/utils.jl
@ -857,17 +857,18 @@ end
|
|||||||
# Some conversion functions
|
# Some conversion functions
|
||||||
# note: I borrowed these conversion constants from Compose.jl's Measure
|
# note: I borrowed these conversion constants from Compose.jl's Measure
|
||||||
|
|
||||||
const PX_PER_INCH = 100
|
const DTPPOINTS_PER_INCH = 72 #Typography (desktop publishing) points per inch
|
||||||
const DPI = PX_PER_INCH
|
const DEFAULT_DPI = DTPPOINTS_PER_INCH
|
||||||
const MM_PER_INCH = 25.4
|
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)
|
inch2mm(inches::Real) = float(inches * MM_PER_INCH)
|
||||||
mm2inch(mm::Real) = float(mm / MM_PER_INCH)
|
mm2inch(mm::Real) = float(mm / MM_PER_INCH)
|
||||||
px2mm(px::Real) = float(px * MM_PER_PX)
|
px2inch(px::Float64, dpi::Float64) = px / dpi
|
||||||
mm2px(mm::Real) = float(px / MM_PER_PX)
|
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"
|
"Smallest x in plot"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user