dpi fixes

This commit is contained in:
Thomas Breloff 2016-06-27 10:06:40 -04:00
parent a3eddf8ba7
commit 928c306803

View File

@ -190,13 +190,13 @@ function py_stepstyle(seriestype::Symbol)
return "default" return "default"
end end
# untested... return a FontProperties object from a Plots.Font # # untested... return a FontProperties object from a Plots.Font
function py_font(font::Font) # function py_font(font::Font)
pyfont.pymember("FontProperties")( # pyfont.pymember("FontProperties")(
family = font.family, # family = font.family,
size = font.size # size = font.size
) # )
end # end
function get_locator_and_formatter(vals::AVec) function get_locator_and_formatter(vals::AVec)
pyticker.pymember("FixedLocator")(1:length(vals)), pyticker.pymember("FixedFormatter")(vals) pyticker.pymember("FixedLocator")(1:length(vals)), pyticker.pymember("FixedFormatter")(vals)
@ -329,6 +329,10 @@ function py_bbox_title(ax)
bb bb
end end
function py_dpi_scale(plt::Plot{PyPlotBackend}, ptsz)
ptsz * DPI / plt[:dpi]
end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# Create the window/figure for this backend. # Create the window/figure for this backend.
@ -421,7 +425,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
label = d[:label], label = d[:label],
zorder = plt.n, zorder = plt.n,
color = py_linecolor(d), color = py_linecolor(d),
linewidth = d[:linewidth], linewidth = py_dpi_scale(plt, d[:linewidth]),
linestyle = py_linestyle(st, d[:linestyle]), linestyle = py_linestyle(st, d[:linestyle]),
solid_capstyle = "round", solid_capstyle = "round",
drawstyle = py_stepstyle(st) drawstyle = py_stepstyle(st)
@ -436,7 +440,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
:label => d[:label], :label => d[:label],
:zorder => plt.n, :zorder => plt.n,
:cmap => py_linecolormap(d), :cmap => py_linecolormap(d),
:linewidth => d[:linewidth], :linewidth => py_dpi_scale(plt, d[:linewidth]),
:linestyle => py_linestyle(st, d[:linestyle]) :linestyle => py_linestyle(st, d[:linestyle])
) )
handle = if is3d(st) handle = if is3d(st)
@ -471,7 +475,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
:shrinkB => 0, :shrinkB => 0,
:edgecolor => py_linecolor(d), :edgecolor => py_linecolor(d),
:facecolor => py_linecolor(d), :facecolor => py_linecolor(d),
:linewidth => d[:linewidth], :linewidth => py_dpi_scale(plt, d[:linewidth]),
:linestyle => py_linestyle(st, d[:linestyle]), :linestyle => py_linestyle(st, d[:linestyle]),
) )
add_arrows(x, y) do xyprev, xy add_arrows(x, y) do xyprev, xy
@ -550,9 +554,9 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
label = d[:label], label = d[:label],
zorder = plt.n + 0.5, zorder = plt.n + 0.5,
marker = py_marker(d[:markershape]), marker = py_marker(d[:markershape]),
s = d[:markersize] .^ 2, s = py_dpi_scale(plt, d[:markersize] .^ 2),
edgecolors = py_markerstrokecolor(d), edgecolors = py_markerstrokecolor(d),
linewidths = d[:markerstrokewidth], linewidths = py_dpi_scale(plt, d[:markerstrokewidth]),
extrakw... extrakw...
) )
push!(handles, handle) push!(handles, handle)
@ -617,7 +621,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
label = d[:label], label = d[:label],
zorder = plt.n, zorder = plt.n,
gridsize = d[:bins], gridsize = d[:bins],
linewidths = d[:linewidth], linewidths = py_dpi_scale(plt, d[:linewidth]),
edgecolors = py_linecolor(d), edgecolors = py_linecolor(d),
cmap = py_fillcolormap(d), # applies to the pcolorfast object cmap = py_fillcolormap(d), # applies to the pcolorfast object
extrakw... extrakw...
@ -657,7 +661,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 = d[:label], label = d[:label],
zorder = plt.n, zorder = plt.n,
linewidths = d[:linewidth], linewidths = py_dpi_scale(plt, d[:linewidth]),
linestyles = py_linestyle(st, d[:linestyle]), linestyles = py_linestyle(st, d[:linestyle]),
cmap = py_linecolormap(d), cmap = py_linecolormap(d),
extrakw... extrakw...
@ -704,7 +708,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
zorder = plt.n, zorder = plt.n,
rstride = 1, rstride = 1,
cstride = 1, cstride = 1,
linewidth = d[:linewidth], linewidth = py_dpi_scale(plt, d[:linewidth]),
edgecolor = py_linecolor(d), edgecolor = py_linecolor(d),
extrakw... extrakw...
) )
@ -740,7 +744,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
label = d[:label], label = d[:label],
zorder = plt.n, zorder = plt.n,
cmap = py_fillcolormap(d), cmap = py_fillcolormap(d),
linewidth = d[:linewidth], linewidth = py_dpi_scale(plt, d[:linewidth]),
edgecolor = py_linecolor(d), edgecolor = py_linecolor(d),
extrakw... extrakw...
) )
@ -819,7 +823,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
zorder = plt.n, zorder = plt.n,
edgecolor = py_linecolor(d), edgecolor = py_linecolor(d),
facecolor = py_fillcolor(d), facecolor = py_fillcolor(d),
linewidth = d[:linewidth], linewidth = py_dpi_scale(plt, d[:linewidth]),
fill = true fill = true
) )
handle = ax[:add_patch](patches) handle = ax[:add_patch](patches)
@ -1012,9 +1016,11 @@ 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]()
fig[:set_size_inches](px2inch(w), px2inch(h), forward = true) # fig[:set_size_inches](px2inch(w), px2inch(h), forward = true)
dpi = plt[:dpi]
fig[:set_size_inches](w/dpi, 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](plt[:dpi]) fig[:set_dpi](dpi)
# resize the window # resize the window
PyPlot.plt[:get_current_fig_manager]()[:resize](w, h) PyPlot.plt[:get_current_fig_manager]()[:resize](w, h)
@ -1052,7 +1058,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](sp[:titlefont].pointsize) ax[func][:set_fontsize](py_dpi_scale(plt, sp[:titlefont].pointsize))
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)
end end
@ -1069,9 +1075,9 @@ 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
ax[axissym][:label][:set_fontsize](axis[:guidefont].pointsize) ax[axissym][:label][:set_fontsize](py_dpi_scale(plt, axis[:guidefont].pointsize))
for lab in ax[Symbol("get_", letter, "ticklabels")]() for lab in ax[Symbol("get_", letter, "ticklabels")]()
lab[:set_fontsize](axis[:tickfont].pointsize) lab[:set_fontsize](py_dpi_scale(plt, axis[:tickfont].pointsize))
lab[:set_rotation](axis[:rotation]) lab[:set_rotation](axis[:rotation])
end end
if sp[:grid] if sp[:grid]
@ -1149,7 +1155,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 = val.font.pointsize, size = py_dpi_scale(sp.plt, val.font.pointsize),
zorder = 999 zorder = 999
) )
end end
@ -1192,7 +1198,7 @@ function py_add_legend(plt::Plot, sp::Subplot, ax)
if should_add_to_legend(series) if should_add_to_legend(series)
# add a line/marker and a label # add a line/marker and a label
push!(handles, if series.d[:seriestype] == :histogram push!(handles, if series.d[:seriestype] == :histogram
PyPlot.plt[:Line2D]((0,1),(0,0), color=py_fillcolor(series.d), linewidth=4) PyPlot.plt[:Line2D]((0,1),(0,0), color=py_fillcolor(series.d), linewidth=py_dpi_scale(plt, 4))
else else
series.d[:serieshandle][1] series.d[:serieshandle][1]
end) end)
@ -1206,7 +1212,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 = sp[:legendfont].pointsize fontsize = py_dpi_scale(plt, sp[:legendfont].pointsize)
# framealpha = 0.6 # framealpha = 0.6
) )
leg[:set_zorder](1000) leg[:set_zorder](1000)