Merge 1439a7e289f12e42a5d17807a8d58cce3da3d958 into 73bd3fa60c24a4206e3b1deb98a13f9763f423fe

This commit is contained in:
Josef Heinen 2016-03-07 15:44:53 +00:00
commit 448e7bcfb2
8 changed files with 200 additions and 86 deletions

View File

@ -4,3 +4,4 @@ Colors
Reexport Reexport
Compat Compat
Requires Requires
FixedSizeArrays

View File

@ -7,6 +7,7 @@ using Compat
using Reexport using Reexport
@reexport using Colors @reexport using Colors
using Requires using Requires
using FixedSizeArrays
export export
Plot, Plot,

View File

@ -31,7 +31,7 @@ function gif(anim::Animation, fn::@compat(AbstractString) = "tmp.gif"; fps::Inte
# high quality # high quality
speed = round(Int, 100 / fps) speed = round(Int, 100 / fps)
run(`convert -delay $speed -loop 0 $(anim.dir)/*.png $fn`) run(`convert -delay $speed -loop 0 $(anim.dir)/*.png -alpha off $fn`)
catch err catch err
warn("Tried to create gif using convert (ImageMagick), but got error: $err\nWill try ffmpeg, but it's lower quality...)") warn("Tried to create gif using convert (ImageMagick), but got error: $err\nWill try ffmpeg, but it's lower quality...)")

View File

@ -1,7 +1,6 @@
# https://github.com/jheinen/GR.jl # https://github.com/jheinen/GR.jl
function _initialize_backend(::GRPackage; kw...) function _initialize_backend(::GRPackage; kw...)
@eval begin @eval begin
import GR import GR
@ -9,15 +8,16 @@ function _initialize_backend(::GRPackage; kw...)
end end
end end
const gr_linetype = Dict( const gr_linetype = Dict(
:auto => 1, :solid => 1, :dash => 2, :dot => 3, :dashdot => 4, :auto => 1, :solid => 1, :dash => 2, :dot => 3, :dashdot => 4,
:dashdotdot => -1 ) :dashdotdot => -1 )
const gr_markertype = Dict( const gr_markertype = Dict(
:auto => 1, :none => -1, :ellipse => -1, :rect => -7, :diamond => -13, :auto => 1, :none => -1, :ellipse => -1, :rect => -7, :diamond => -13,
:utriangle => -3, :dtriangle => -5, :pentagon => -14, :hexagon => 3, :utriangle => -3, :dtriangle => -5, :pentagon => -21, :hexagon => -22,
:cross => 2, :xcross => 5, :star5 => 3 ) :heptagon => -23, :octagon => -24, :cross => 2, :xcross => 5,
:star4 => -25, :star5 => -26, :star6 => -27, :star7 => -28, :star8 => -29,
:vline => -30, :hline => -31 )
const gr_halign = Dict(:left => 1, :hcenter => 2, :right => 3) const gr_halign = Dict(:left => 1, :hcenter => 2, :right => 3)
const gr_valign = Dict(:top => 1, :vcenter => 3, :bottom => 5) const gr_valign = Dict(:top => 1, :vcenter => 3, :bottom => 5)
@ -54,21 +54,43 @@ function gr_display(plt::Plot{GRPackage}, clear=true, update=true,
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.1 * (subplot[2] - subplot[1]) viewport[1] = subplot[1] + 0.125 * (subplot[2] - subplot[1])
viewport[2] = subplot[1] + 0.95 * (subplot[2] - subplot[1]) viewport[2] = subplot[1] + 0.95 * (subplot[2] - subplot[1])
viewport[3] = ratio * (subplot[3] + 0.1 * (subplot[4] - subplot[3])) viewport[3] = ratio * (subplot[3] + 0.125 * (subplot[4] - subplot[3]))
viewport[4] = ratio * (subplot[3] + 0.95 * (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.1 * (subplot[2] - subplot[1])) viewport[1] = ratio * (subplot[1] + 0.125 * (subplot[2] - subplot[1]))
viewport[2] = ratio * (subplot[1] + 0.95 * (subplot[2] - subplot[1])) viewport[2] = ratio * (subplot[1] + 0.95 * (subplot[2] - subplot[1]))
viewport[3] = subplot[3] + 0.1 * (subplot[4] - subplot[3]) viewport[3] = subplot[3] + 0.125 * (subplot[4] - subplot[3])
viewport[4] = subplot[3] + 0.95 * (subplot[4] - subplot[3]) viewport[4] = subplot[3] + 0.95 * (subplot[4] - subplot[3])
end end
if haskey(d, :background_color)
GR.savestate()
GR.selntran(0)
GR.setfillintstyle(GR.INTSTYLE_SOLID)
GR.setfillcolorind(gr_getcolorind(d[:background_color]))
if w > h
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.restorestate()
c = getColor(d[:background_color])
if 0.21 * c.r + 0.72 * c.g + 0.07 * c.b < 0.9
fg = convert(Int, GR.inqcolorfromrgb(1-c.r, 1-c.g, 1-c.b))
else
fg = 1
end
else
fg = 1
end
extrema = zeros(2, 4) extrema = zeros(2, 4)
num_axes = 1 num_axes = 1
cmap = false cmap = false
@ -99,6 +121,10 @@ function gr_display(plt::Plot{GRPackage}, clear=true, update=true,
end end
cmap = true cmap = true
x, y, H = Base.hist2d(E, xbins, ybins) x, y, H = Base.hist2d(E, xbins, ybins)
elseif p[:linetype] == :pie
axes_2d = false
xmin, xmax, ymin, ymax = 0, 1, 0, 1
x, y = p[:x], p[:y]
else else
if p[:linetype] in [:contour, :surface] if p[:linetype] in [:contour, :surface]
cmap = true cmap = true
@ -108,6 +134,7 @@ function gr_display(plt::Plot{GRPackage}, clear=true, update=true,
end end
x, y = p[:x], p[:y] x, y = p[:x], p[:y]
end end
if p[:linetype] != :pie
xmin = min(minimum(x), xmin) xmin = min(minimum(x), xmin)
xmax = max(maximum(x), xmax) xmax = max(maximum(x), xmax)
if p[:linetype] == :ohlc if p[:linetype] == :ohlc
@ -121,18 +148,30 @@ function gr_display(plt::Plot{GRPackage}, clear=true, update=true,
end end
end end
end end
end
if xmax <= xmin
xmax = xmin + 1
end
if ymax <= ymin
ymax = ymin + 1
end
extrema[axis,:] = [xmin, xmax, ymin, ymax] extrema[axis,:] = [xmin, xmax, ymin, ymax]
end end
if num_axes == 2 || !axes_2d if num_axes == 2 || !axes_2d
viewport[2] -= 0.05 viewport[2] -= 0.0525
end end
if cmap if cmap
viewport[2] -= 0.1 viewport[2] -= 0.1
end end
GR.setviewport(viewport[1], viewport[2], viewport[3], viewport[4]) GR.setviewport(viewport[1], viewport[2], viewport[3], viewport[4])
scale = d[:scale] scale = 0
d[:xscale] == :log10 && (scale |= GR.OPTION_X_LOG)
d[:yscale] == :log10 && (scale |= GR.OPTION_Y_LOG)
get(d, :xflip, false) && (scale |= GR.OPTION_FLIP_X)
get(d, :yflip, false) && (scale |= GR.OPTION_FLIP_Y)
for axis = 1:num_axes for axis = 1:num_axes
xmin, xmax, ymin, ymax = extrema[axis,:] xmin, xmax, ymin, ymax = extrema[axis,:]
if scale & GR.OPTION_X_LOG == 0 if scale & GR.OPTION_X_LOG == 0
@ -161,22 +200,20 @@ function gr_display(plt::Plot{GRPackage}, clear=true, update=true,
end end
GR.setwindow(xmin, xmax, ymin, ymax) GR.setwindow(xmin, xmax, ymin, ymax)
if axis == 1 && haskey(d, :background_color)
GR.savestate()
GR.setfillintstyle(GR.INTSTYLE_SOLID)
GR.setfillcolorind(gr_getcolorind(d[:background_color]))
GR.fillrect(xmin, xmax, ymin, ymax)
GR.restorestate()
end
GR.setscale(scale) GR.setscale(scale)
if axes_2d
diag = sqrt((viewport[2] - viewport[1])^2 + (viewport[4] - viewport[3])^2) diag = sqrt((viewport[2] - viewport[1])^2 + (viewport[4] - viewport[3])^2)
GR.setlinewidth(1)
charheight = max(0.018 * diag, 0.01) charheight = max(0.018 * diag, 0.01)
GR.setcharheight(charheight) GR.setcharheight(charheight)
GR.settextcolorind(fg)
if axes_2d
GR.setlinewidth(1)
GR.setlinecolorind(fg)
ticksize = 0.0075 * diag ticksize = 0.0075 * diag
if fg == 1
GR.grid(xtick, ytick, 0, 0, majorx, majory) GR.grid(xtick, ytick, 0, 0, majorx, majory)
end
if num_axes == 1 if num_axes == 1
GR.axes(xtick, ytick, xorg[1], yorg[1], majorx, majory, ticksize) GR.axes(xtick, ytick, xorg[1], yorg[1], majorx, majory, ticksize)
GR.axes(xtick, ytick, xorg[2], yorg[2], -majorx, -majory, -ticksize) GR.axes(xtick, ytick, xorg[2], yorg[2], -majorx, -majory, -ticksize)
@ -191,19 +228,22 @@ function gr_display(plt::Plot{GRPackage}, clear=true, update=true,
if get(d, :title, "") != "" if get(d, :title, "") != ""
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.text(0.5, min(ratio, 1), d[:title]) GR.settextcolorind(fg)
GR.text(0.5 * (viewport[1] + viewport[2]), min(ratio, 1), 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.text(0.5, 0, d[:xlabel]) GR.settextcolorind(fg)
GR.text(0.5 * (viewport[1] + viewport[2]), 0, d[:xlabel])
GR.restorestate() GR.restorestate()
end end
if get(d, :ylabel, "") != "" if get(d, :ylabel, "") != ""
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.setcharup(-1, 0) GR.setcharup(-1, 0)
GR.settextcolorind(fg)
GR.text(0, 0.5 * (viewport[3] + viewport[4]), d[:ylabel]) GR.text(0, 0.5 * (viewport[3] + viewport[4]), d[:ylabel])
GR.restorestate() GR.restorestate()
end end
@ -211,6 +251,7 @@ function gr_display(plt::Plot{GRPackage}, 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.setcharup(1, 0) GR.setcharup(1, 0)
GR.settextcolorind(fg)
GR.text(1, 0.5 * (viewport[3] + viewport[4]), d[:yrightlabel]) GR.text(1, 0.5 * (viewport[3] + viewport[4]), d[:yrightlabel])
GR.restorestate() GR.restorestate()
end end
@ -231,14 +272,18 @@ function gr_display(plt::Plot{GRPackage}, clear=true, update=true,
GR.setfillcolorind(gr_getcolorind(p[:fillcolor])) GR.setfillcolorind(gr_getcolorind(p[:fillcolor]))
GR.setfillintstyle(GR.INTSTYLE_SOLID) GR.setfillintstyle(GR.INTSTYLE_SOLID)
end end
if length(p[:x]) > 1
if p[:fillrange] != nothing if p[:fillrange] != nothing
GR.fillarea([p[:x][1]; p[:x]; p[:x][length(p[:x])]], [p[:fillrange]; p[:y]; p[:fillrange]]) GR.fillarea([p[:x][1]; p[:x]; p[:x][length(p[:x])]], [p[:fillrange]; p[:y]; p[:fillrange]])
end end
GR.polyline(p[:x], p[:y]) GR.polyline(p[:x], p[:y])
end
legend = true legend = true
end end
if p[:linetype] == :line if p[:linetype] == :line
if length(p[:x]) > 1
GR.polyline(p[:x], p[:y]) GR.polyline(p[:x], p[:y])
end
legend = true legend = true
elseif p[:linetype] in [:steppre, :steppost] elseif p[:linetype] in [:steppre, :steppost]
n = length(p[:x]) n = length(p[:x])
@ -256,7 +301,9 @@ function gr_display(plt::Plot{GRPackage}, clear=true, update=true,
end end
j += 2 j += 2
end end
if n > 1
GR.polyline(x, y) GR.polyline(x, y)
end
legend = true legend = true
elseif p[:linetype] == :sticks elseif p[:linetype] == :sticks
x, y = p[:x], p[:y] x, y = p[:x], p[:y]
@ -270,7 +317,9 @@ function gr_display(plt::Plot{GRPackage}, clear=true, update=true,
if haskey(d, :markersize) if haskey(d, :markersize)
if typeof(d[:markersize]) <: Number if typeof(d[:markersize]) <: Number
GR.setmarkersize(d[:markersize] / 4.0) GR.setmarkersize(d[:markersize] / 4.0)
if length(p[:x]) > 0
GR.polymarker(p[:x], p[:y]) GR.polymarker(p[:x], p[:y])
end
else else
c = p[:markercolor] c = p[:markercolor]
GR.setcolormap(-GR.COLORMAP_GLOWING) GR.setcolormap(-GR.COLORMAP_GLOWING)
@ -284,8 +333,10 @@ function gr_display(plt::Plot{GRPackage}, clear=true, update=true,
end end
end end
else else
if length(p[:x]) > 0
GR.polymarker(p[:x], p[:y]) GR.polymarker(p[:x], p[:y])
end end
end
legend = true legend = true
elseif p[:linetype] == :bar elseif p[:linetype] == :bar
y = p[:y] y = p[:y]
@ -368,11 +419,9 @@ function gr_display(plt::Plot{GRPackage}, clear=true, update=true,
diag = sqrt((viewport[2] - viewport[1])^2 + (viewport[4] - viewport[3])^2) diag = sqrt((viewport[2] - viewport[1])^2 + (viewport[4] - viewport[3])^2)
charheight = max(0.018 * diag, 0.01) charheight = max(0.018 * diag, 0.01)
ticksize = 0.01 * (viewport[2] - viewport[1]) ticksize = 0.01 * (viewport[2] - viewport[1])
# GR.savestate()
GR.setlinewidth(1) GR.setlinewidth(1)
GR.grid3d(xtick, 0, ztick, xmin, ymin, zmin, 2, 0, 2) GR.grid3d(xtick, 0, ztick, xmin, ymin, zmin, 2, 0, 2)
GR.grid3d(0, ytick, 0, xmax, ymin, zmin, 0, 2, 0) GR.grid3d(0, ytick, 0, xmax, ymin, zmin, 0, 2, 0)
# GR.restorestate()
z = reshape(z, length(x) * length(y)) z = reshape(z, length(x) * length(y))
if p[:linetype] == :surface if p[:linetype] == :surface
GR.setcolormap(GR.COLORMAP_COOLWARM) GR.setcolormap(GR.COLORMAP_COOLWARM)
@ -400,11 +449,11 @@ function gr_display(plt::Plot{GRPackage}, clear=true, update=true,
diag = sqrt((viewport[2] - viewport[1])^2 + (viewport[4] - viewport[3])^2) diag = sqrt((viewport[2] - viewport[1])^2 + (viewport[4] - viewport[3])^2)
charheight = max(0.018 * diag, 0.01) charheight = max(0.018 * diag, 0.01)
ticksize = 0.01 * (viewport[2] - viewport[1]) ticksize = 0.01 * (viewport[2] - viewport[1])
# GR.savestate()
GR.setlinewidth(1) GR.setlinewidth(1)
if p[:linetype] == :path3d
GR.grid3d(xtick, 0, ztick, xmin, ymin, zmin, 2, 0, 2) GR.grid3d(xtick, 0, ztick, xmin, ymin, zmin, 2, 0, 2)
GR.grid3d(0, ytick, 0, xmax, ymin, zmin, 0, 2, 0) GR.grid3d(0, ytick, 0, xmax, ymin, zmin, 0, 2, 0)
# GR.restorestate() end
if p[:linetype] == :scatter3d if p[:linetype] == :scatter3d
haskey(p, :markercolor) && GR.setmarkercolorind(gr_getcolorind(p[:markercolor])) haskey(p, :markercolor) && GR.setmarkercolorind(gr_getcolorind(p[:markercolor]))
haskey(p, :markershape) && GR.setmarkertype(gr_markertype[p[:markershape]]) haskey(p, :markershape) && GR.setmarkertype(gr_markertype[p[:markershape]])
@ -414,8 +463,10 @@ function gr_display(plt::Plot{GRPackage}, clear=true, update=true,
end end
else else
haskey(p, :linewidth) && GR.setlinewidth(p[:linewidth]) haskey(p, :linewidth) && GR.setlinewidth(p[:linewidth])
if length(x) > 0
GR.polyline3d(x, y, z) GR.polyline3d(x, y, z)
end end
end
GR.setlinewidth(1) GR.setlinewidth(1)
GR.setcharheight(charheight) GR.setcharheight(charheight)
GR.axes3d(xtick, 0, ztick, xmin, ymin, zmin, 2, 0, 2, -ticksize) GR.axes3d(xtick, 0, ztick, xmin, ymin, zmin, 2, 0, 2, -ticksize)
@ -429,8 +480,33 @@ function gr_display(plt::Plot{GRPackage}, clear=true, update=true,
GR.polyline([i, i], [y[i].low, y[i].high]) GR.polyline([i, i], [y[i].low, y[i].high])
GR.polyline([i, i+ticksize], [y[i].close, y[i].close]) GR.polyline([i, i+ticksize], [y[i].close, y[i].close])
end end
elseif p[:linetype] in [:pie] elseif p[:linetype] == :pie
println("TODO: add support for linetype $(p[:linetype])") GR.selntran(0)
GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_HALF)
GR.setfillintstyle(GR.INTSTYLE_SOLID)
xmin, xmax, ymin, ymax = viewport
ymax -= 0.05 * (xmax - xmin)
xcenter = 0.5 * (xmin + xmax)
ycenter = 0.5 * (ymin + ymax)
if xmax - xmin > ymax - ymin
r = 0.5 * (ymax - ymin)
xmin, xmax = xcenter - r, xcenter + r
else
r = 0.5 * (xmax - xmin)
ymin, ymax = ycenter - r, ycenter + r
end
x, y = p[:x], p[:y]
total = sum(y)
a1 = 0
for i in 1:length(y)
a2 = round(Int, a1 + (y[i] / total) * 360.0)
GR.setfillcolorind(980 + (i-1) % 20)
GR.fillarc(xmin, xmax, ymin, ymax, a1, a2)
GR.text(xcenter + 0.5 * r * cos(0.5 * (a1 + a2) * pi / 180),
ycenter + 0.5 * r * sin(0.5 * (a1 + a2) * pi / 180), string(x[i]))
a1 = a2
end
GR.selntran(1)
end end
GR.restorestate() GR.restorestate()
end end
@ -453,13 +529,13 @@ function gr_display(plt::Plot{GRPackage}, clear=true, update=true,
end end
px = viewport[2] - 0.05 - w px = viewport[2] - 0.05 - w
py = viewport[4] - 0.06 py = viewport[4] - 0.06
dy = 0.03 * sqrt((viewport[2] - viewport[1])^2 + (viewport[4] - viewport[3])^2)
GR.setfillintstyle(GR.INTSTYLE_SOLID) GR.setfillintstyle(GR.INTSTYLE_SOLID)
GR.setfillcolorind(0) GR.setfillcolorind(0)
GR.fillrect(px - 0.08, px + w + 0.02, py + 0.03, py - 0.03 * length(plt.seriesargs)) GR.fillrect(px - 0.08, px + w + 0.02, py + dy, py - dy * length(plt.seriesargs))
GR.setlinetype(1) GR.setlinetype(1)
GR.setlinecolorind(1)
GR.setlinewidth(1) GR.setlinewidth(1)
GR.drawrect(px - 0.08, px + w + 0.02, py + 0.03, py - 0.03 * length(plt.seriesargs)) GR.drawrect(px - 0.08, px + w + 0.02, py + dy, py - dy * length(plt.seriesargs))
haskey(d, :linewidth) && GR.setlinewidth(d[:linewidth]) haskey(d, :linewidth) && GR.setlinewidth(d[:linewidth])
i = 0 i = 0
for p in plt.seriesargs for p in plt.seriesargs
@ -484,8 +560,9 @@ function gr_display(plt::Plot{GRPackage}, clear=true, update=true,
lab = p[:label] lab = p[:label]
end end
GR.settextalign(GR.TEXT_HALIGN_LEFT, GR.TEXT_VALIGN_HALF) GR.settextalign(GR.TEXT_HALIGN_LEFT, GR.TEXT_VALIGN_HALF)
GR.settextcolorind(1)
GR.text(px, py, lab) GR.text(px, py, lab)
py -= 0.03 py -= dy
end end
GR.selntran(1) GR.selntran(1)
GR.restorestate() GR.restorestate()
@ -530,7 +607,6 @@ function gr_display(subplt::Subplot{GRPackage})
end end
function _create_plot(pkg::GRPackage; kw...) function _create_plot(pkg::GRPackage; kw...)
isijulia() && GR.inline("svg")
d = Dict(kw) d = Dict(kw)
Plot(nothing, pkg, 0, d, Dict[]) Plot(nothing, pkg, 0, d, Dict[])
end end
@ -555,13 +631,6 @@ function _before_update_plot(plt::Plot{GRPackage})
end end
function _update_plot(plt::Plot{GRPackage}, d::Dict) function _update_plot(plt::Plot{GRPackage}, d::Dict)
scale = 0
d[:xscale] == :log10 && (scale |= GR.OPTION_X_LOG)
d[:yscale] == :log10 && (scale |= GR.OPTION_Y_LOG)
get(d, :xflip, false) && (scale |= GR.OPTION_FLIP_X)
get(d, :yflip, false) && (scale |= GR.OPTION_FLIP_Y)
plt.plotargs[:scale] = scale
for k in (:title, :xlabel, :ylabel) for k in (:title, :xlabel, :ylabel)
haskey(d, k) && (plt.plotargs[k] = d[k]) haskey(d, k) && (plt.plotargs[k] = d[k])
end end
@ -600,6 +669,7 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function Base.writemime(io::IO, m::MIME"image/png", plt::PlottingObject{GRPackage}) function Base.writemime(io::IO, m::MIME"image/png", plt::PlottingObject{GRPackage})
GR.emergencyclosegks()
ENV["GKS_WSTYPE"] = "png" ENV["GKS_WSTYPE"] = "png"
gr_display(plt) gr_display(plt)
GR.emergencyclosegks() GR.emergencyclosegks()
@ -607,13 +677,29 @@ function Base.writemime(io::IO, m::MIME"image/png", plt::PlottingObject{GRPackag
end end
function Base.writemime(io::IO, m::MIME"image/svg+xml", plt::PlottingObject{GRPackage}) function Base.writemime(io::IO, m::MIME"image/svg+xml", plt::PlottingObject{GRPackage})
isijulia() || return GR.emergencyclosegks()
ENV["GKS_WSTYPE"] = "svg" ENV["GKS_WSTYPE"] = "svg"
gr_display(plt) gr_display(plt)
GR.emergencyclosegks() GR.emergencyclosegks()
write(io, readall("gks.svg")) write(io, readall("gks.svg"))
end end
function Base.writemime(io::IO, m::MIME"application/pdf", plt::PlottingObject{GRPackage})
GR.emergencyclosegks()
ENV["GKS_WSTYPE"] = "pdf"
gr_display(plt)
GR.emergencyclosegks()
write(io, readall("gks.pdf"))
end
function Base.writemime(io::IO, m::MIME"application/postscript", plt::PlottingObject{GRPackage})
GR.emergencyclosegks()
ENV["GKS_WSTYPE"] = "ps"
gr_display(plt)
GR.emergencyclosegks()
write(io, readall("gks.ps"))
end
function Base.display(::PlotsDisplay, plt::Plot{GRPackage}) function Base.display(::PlotsDisplay, plt::Plot{GRPackage})
gr_display(plt) gr_display(plt)
end end

View File

@ -45,8 +45,8 @@ function getPyPlotColorMap(c::ColorGradient, α=nothing)
pycolors.pymember("LinearSegmentedColormap")[:from_list]("tmp", pyvals) pycolors.pymember("LinearSegmentedColormap")[:from_list]("tmp", pyvals)
end end
# anything else just gets a redsblue gradient # anything else just gets a bluesred gradient
getPyPlotColorMap(c, α=nothing) = getPyPlotColorMap(ColorGradient(:redsblues), α) getPyPlotColorMap(c, α=nothing) = getPyPlotColorMap(ColorGradient(:bluesreds), α)
# get the style (solid, dashed, etc) # get the style (solid, dashed, etc)
function getPyPlotLineStyle(linetype::Symbol, linestyle::Symbol) function getPyPlotLineStyle(linetype::Symbol, linestyle::Symbol)
@ -461,25 +461,49 @@ function Base.getindex(plt::Plot{PyPlotPackage}, i::Integer)
end end
end end
function minmaxseries(ds, vec, axis)
lo, hi = Inf, -Inf
for d in ds
d[:axis] == axis || continue
v = d[vec]
if length(v) > 0
vlo, vhi = extrema(v)
lo = min(lo, vlo)
hi = max(hi, vhi)
end
end
if lo == hi
hi = if lo == 0
1e-6
else
hi + min(abs(1e-2hi), 1e-6)
end
end
lo, hi
end
function set_lims!(plt::Plot{PyPlotPackage}, axis::Symbol)
ax = getAxis(plt, axis)
if plt.plotargs[:xlims] == :auto
ax[:set_xlim](minmaxseries(plt.seriesargs, :x, axis)...)
end
if plt.plotargs[:ylims] == :auto
ax[:set_ylim](minmaxseries(plt.seriesargs, :y, axis)...)
end
end
function Base.setindex!{X,Y}(plt::Plot{PyPlotPackage}, xy::Tuple{X,Y}, i::Integer) function Base.setindex!{X,Y}(plt::Plot{PyPlotPackage}, xy::Tuple{X,Y}, i::Integer)
series = plt.seriesargs[i][:serieshandle] d = plt.seriesargs[i]
series = d[:serieshandle]
x, y = xy x, y = xy
d[:x], d[:y] = x, y
try try
series[:set_data](x, y) series[:set_data](x, y)
catch catch
series[:set_offsets](hcat(x, y)) series[:set_offsets](hcat(x, y))
end end
ax = series[:axes] set_lims!(plt, d[:axis])
if plt.plotargs[:xlims] == :auto
xmin, xmax = ax[:get_xlim]()
ax[:set_xlim](min(xmin, minimum(x)), max(xmax, maximum(x)))
end
if plt.plotargs[:ylims] == :auto
ymin, ymax = ax[:get_ylim]()
ax[:set_ylim](min(ymin, minimum(y)), max(ymax, maximum(y)))
end
plt plt
end end

View File

@ -189,6 +189,7 @@ supportedArgs(::GRPackage) = [
:label, :label,
:layout, :layout,
:legend, :legend,
:colorbar,
:linestyle, :linestyle,
:linetype, :linetype,
:linewidth, :linewidth,
@ -239,8 +240,8 @@ supportedTypes(::GRPackage) = [:none, :line, :path, :steppre, :steppost, :sticks
:scatter, :heatmap, :hexbin, :hist, :density, :bar, :scatter, :heatmap, :hexbin, :hist, :density, :bar,
:hline, :vline, :contour, :path3d, :scatter3d, :surface, :hline, :vline, :contour, :path3d, :scatter3d, :surface,
:wireframe, :ohlc, :pie] :wireframe, :ohlc, :pie]
supportedStyles(::GRPackage) = [:auto, :solid, :dash, :dot, :dashdot] supportedStyles(::GRPackage) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
supportedMarkers(::GRPackage) = vcat([:none, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :pentagon, :hexagon, :cross, :xcross, :star5], Shape) supportedMarkers(::GRPackage) = vcat(_allMarkers, Shape)
supportedScales(::GRPackage) = [:identity, :log10] supportedScales(::GRPackage) = [:identity, :log10]
subplotSupported(::GRPackage) = true subplotSupported(::GRPackage) = true

View File

@ -244,7 +244,7 @@ type OHLC{T<:Real}
end end
@require FixedSizeArrays begin # @require FixedSizeArrays begin
export export
P2, P2,
@ -309,4 +309,4 @@ end
BezierCurve([p, upper_control, inside_control_points..., lower_control, q]) BezierCurve([p, upper_control, inside_control_points..., lower_control, q])
end end
end # end

View File

@ -262,7 +262,8 @@ function convertToAnyVector(v::AVec; kw...)
Any[convert(Vector{Float64}, v)], nothing Any[convert(Vector{Float64}, v)], nothing
else else
# something else... treat each element as an item # something else... treat each element as an item
Any[vi for vi in v], nothing vcat(Any[convertToAnyVector(vi)[1] for vi in v]...), nothing
# Any[vi for vi in v], nothing
end end
end end
@ -483,7 +484,7 @@ end
# -------------------------------------------------------------------- # --------------------------------------------------------------------
@require FixedSizeArrays begin # @require FixedSizeArrays begin
unzip{T}(x::AVec{FixedSizeArrays.Vec{2,T}}) = T[xi[1] for xi in x], T[xi[2] for xi in x] unzip{T}(x::AVec{FixedSizeArrays.Vec{2,T}}) = T[xi[1] for xi in x], T[xi[2] for xi in x]
unzip{T}(x::FixedSizeArrays.Vec{2,T}) = T[x[1]], T[x[2]] unzip{T}(x::FixedSizeArrays.Vec{2,T}) = T[x[1]], T[x[2]]
@ -496,7 +497,7 @@ end
createKWargsList(plt, [xy[1]], [xy[2]]; kw...) createKWargsList(plt, [xy[1]], [xy[2]]; kw...)
end end
end # end
# -------------------------------------------------------------------- # --------------------------------------------------------------------