gr: improved subplot layout
This commit is contained in:
parent
7531c48e38
commit
97faa7413f
@ -98,36 +98,36 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
|
|||||||
mwidth, mheight, width, height = GR.inqdspsize()
|
mwidth, mheight, width, height = GR.inqdspsize()
|
||||||
w, h = d[:size]
|
w, h = d[:size]
|
||||||
viewport = zeros(4)
|
viewport = zeros(4)
|
||||||
|
vp = float(subplot)
|
||||||
if w > h
|
if w > h
|
||||||
ratio = float(h) / w
|
ratio = float(h) / w
|
||||||
msize = mwidth * w / width
|
msize = mwidth * w / width
|
||||||
GR.setwsviewport(0, msize, 0, msize * ratio)
|
GR.setwsviewport(0, msize, 0, msize * ratio)
|
||||||
GR.setwswindow(0, 1, 0, ratio)
|
GR.setwswindow(0, 1, 0, ratio)
|
||||||
viewport[1] = subplot[1] + 0.125 * (subplot[2] - subplot[1])
|
vp[3] *= ratio
|
||||||
viewport[2] = subplot[1] + 0.95 * (subplot[2] - subplot[1])
|
vp[4] *= ratio
|
||||||
viewport[3] = ratio * (subplot[3] + 0.125 * (subplot[4] - subplot[3]))
|
|
||||||
viewport[4] = ratio * (subplot[3] + 0.95 * (subplot[4] - subplot[3]))
|
|
||||||
else
|
else
|
||||||
ratio = float(w) / h
|
ratio = float(w) / h
|
||||||
msize = mheight * h / height
|
msize = mheight * h / height
|
||||||
GR.setwsviewport(0, msize * ratio, 0, msize)
|
GR.setwsviewport(0, msize * ratio, 0, msize)
|
||||||
GR.setwswindow(0, ratio, 0, 1)
|
GR.setwswindow(0, ratio, 0, 1)
|
||||||
viewport[1] = ratio * (subplot[1] + 0.125 * (subplot[2] - subplot[1]))
|
vp[1] *= ratio
|
||||||
viewport[2] = ratio * (subplot[1] + 0.95 * (subplot[2] - subplot[1]))
|
vp[2] *= ratio
|
||||||
viewport[3] = subplot[3] + 0.125 * (subplot[4] - subplot[3])
|
|
||||||
viewport[4] = subplot[3] + 0.95 * (subplot[4] - subplot[3])
|
|
||||||
end
|
end
|
||||||
|
viewport[1] = vp[1] + 0.125 * (vp[2] - vp[1])
|
||||||
|
viewport[2] = vp[1] + 0.95 * (vp[2] - vp[1])
|
||||||
|
viewport[3] = vp[3] + 0.125 * (vp[4] - vp[3])
|
||||||
|
if w > h
|
||||||
|
viewport[3] += (1 - (subplot[4] - subplot[3])^2) * 0.02
|
||||||
|
end
|
||||||
|
viewport[4] = vp[3] + 0.95 * (vp[4] - vp[3])
|
||||||
|
|
||||||
if haskey(d, :background_color)
|
if haskey(d, :background_color)
|
||||||
GR.savestate()
|
GR.savestate()
|
||||||
GR.selntran(0)
|
GR.selntran(0)
|
||||||
GR.setfillintstyle(GR.INTSTYLE_SOLID)
|
GR.setfillintstyle(GR.INTSTYLE_SOLID)
|
||||||
GR.setfillcolorind(gr_getcolorind(d[:background_color]))
|
GR.setfillcolorind(gr_getcolorind(d[:background_color]))
|
||||||
if w > h
|
GR.fillrect(vp[1], vp[2], vp[3], vp[4])
|
||||||
GR.fillrect(subplot[1], subplot[2], ratio*subplot[3], ratio*subplot[4])
|
|
||||||
else
|
|
||||||
GR.fillrect(ratio*subplot[1], ratio*subplot[2], subplot[3], subplot[4])
|
|
||||||
end
|
|
||||||
GR.selntran(1)
|
GR.selntran(1)
|
||||||
GR.restorestate()
|
GR.restorestate()
|
||||||
c = getColor(d[:background_color])
|
c = getColor(d[:background_color])
|
||||||
@ -160,7 +160,7 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
|
|||||||
x, y = 1:size(p[:y], 1), p[:y]
|
x, y = 1:size(p[:y], 1), p[:y]
|
||||||
elseif p[:linetype] in [:hist, :density]
|
elseif p[:linetype] in [:hist, :density]
|
||||||
x, y = Base.hist(p[:y])
|
x, y = Base.hist(p[:y])
|
||||||
elseif p[:linetype] in [:hist2d, :hexbin]
|
elseif p[:linetype] in [:heatmap, :hexbin]
|
||||||
E = zeros(length(p[:x]),2)
|
E = zeros(length(p[:x]),2)
|
||||||
E[:,1] = p[:x]
|
E[:,1] = p[:x]
|
||||||
E[:,2] = p[:y]
|
E[:,2] = p[:y]
|
||||||
@ -285,14 +285,14 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
|
|||||||
GR.savestate()
|
GR.savestate()
|
||||||
GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_TOP)
|
GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_TOP)
|
||||||
GR.settextcolorind(fg)
|
GR.settextcolorind(fg)
|
||||||
GR.text(0.5 * (viewport[1] + viewport[2]), min(ratio, 1), d[:title])
|
GR.text(0.5 * (viewport[1] + viewport[2]), vp[4], d[:title])
|
||||||
GR.restorestate()
|
GR.restorestate()
|
||||||
end
|
end
|
||||||
if get(d, :xlabel, "") != ""
|
if get(d, :xlabel, "") != ""
|
||||||
GR.savestate()
|
GR.savestate()
|
||||||
GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_BOTTOM)
|
GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_BOTTOM)
|
||||||
GR.settextcolorind(fg)
|
GR.settextcolorind(fg)
|
||||||
GR.text(0.5 * (viewport[1] + viewport[2]), 0, d[:xlabel])
|
GR.text(0.5 * (viewport[1] + viewport[2]), vp[3], d[:xlabel])
|
||||||
GR.restorestate()
|
GR.restorestate()
|
||||||
end
|
end
|
||||||
if get(d, :ylabel, "") != ""
|
if get(d, :ylabel, "") != ""
|
||||||
@ -300,7 +300,7 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
|
|||||||
GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_TOP)
|
GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_TOP)
|
||||||
GR.setcharup(-1, 0)
|
GR.setcharup(-1, 0)
|
||||||
GR.settextcolorind(fg)
|
GR.settextcolorind(fg)
|
||||||
GR.text(0, 0.5 * (viewport[3] + viewport[4]), d[:ylabel])
|
GR.text(vp[1], 0.5 * (viewport[3] + viewport[4]), d[:ylabel])
|
||||||
GR.restorestate()
|
GR.restorestate()
|
||||||
end
|
end
|
||||||
if get(d, :yrightlabel, "") != ""
|
if get(d, :yrightlabel, "") != ""
|
||||||
@ -308,7 +308,7 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
|
|||||||
GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_TOP)
|
GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_TOP)
|
||||||
GR.setcharup(1, 0)
|
GR.setcharup(1, 0)
|
||||||
GR.settextcolorind(fg)
|
GR.settextcolorind(fg)
|
||||||
GR.text(1, 0.5 * (viewport[3] + viewport[4]), d[:yrightlabel])
|
GR.text(vp[2], 0.5 * (viewport[3] + viewport[4]), d[:yrightlabel])
|
||||||
GR.restorestate()
|
GR.restorestate()
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -423,7 +423,7 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
|
|||||||
GR.polyline([xy, xy], [ymin, ymax])
|
GR.polyline([xy, xy], [ymin, ymax])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif p[:linetype] in [:hist2d, :hexbin]
|
elseif p[:linetype] in [:heatmap, :hexbin]
|
||||||
E = zeros(length(p[:x]),2)
|
E = zeros(length(p[:x]),2)
|
||||||
E[:,1] = p[:x]
|
E[:,1] = p[:x]
|
||||||
E[:,2] = p[:y]
|
E[:,2] = p[:y]
|
||||||
|
|||||||
@ -241,7 +241,7 @@ supportedArgs(::GRBackend) = [
|
|||||||
supportedAxes(::GRBackend) = _allAxes
|
supportedAxes(::GRBackend) = _allAxes
|
||||||
supportedTypes(::GRBackend) = [:none, :line, :path, :steppre, :steppost, :sticks,
|
supportedTypes(::GRBackend) = [:none, :line, :path, :steppre, :steppost, :sticks,
|
||||||
:scatter, :hist2d, :hexbin, :hist, :density, :bar,
|
:scatter, :hist2d, :hexbin, :hist, :density, :bar,
|
||||||
:hline, :vline, :contour, :path3d, :scatter3d, :surface,
|
:hline, :vline, :contour, :heatmap, :path3d, :scatter3d, :surface,
|
||||||
:wireframe, :ohlc, :pie]
|
:wireframe, :ohlc, :pie]
|
||||||
supportedStyles(::GRBackend) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
|
supportedStyles(::GRBackend) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
|
||||||
supportedMarkers(::GRBackend) = vcat(_allMarkers, Shape)
|
supportedMarkers(::GRBackend) = vcat(_allMarkers, Shape)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user