From b4fb9af8e49065aa4c57eaacce0a88d3034ca19e Mon Sep 17 00:00:00 2001 From: Josef Heinen Date: Fri, 29 Apr 2016 12:05:06 +0200 Subject: [PATCH 1/4] Fixed a problem with Julia v0.3 --- src/backends/gr.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 27a2512e..6c4f93f9 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -135,6 +135,7 @@ end function gr_polaraxes(rmin, rmax) GR.savestate() + GR.setlinetype(GR.LINETYPE_SOLID) GR.setlinecolorind(88) tick = 0.5 * GR.tick(rmin, rmax) n = round(Int, (rmax - rmin) / tick + 0.5) @@ -147,9 +148,10 @@ function gr_polaraxes(rmin, rmax) end GR.settextalign(GR.TEXT_HALIGN_LEFT, GR.TEXT_VALIGN_HALF) x, y = GR.wctondc(0.05, r) - GR.text(x, y, @sprintf("%g", rmin + i * tick)) + GR.text(x, y, string(signif(rmin + i * tick, 12))) else GR.setlinecolorind(90) + GR.drawarc(-r, r, -r, r, 0, 359) end end for alpha in 0:45:315 @@ -695,7 +697,7 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true, GR.setwindow(-1, 1, -1, 1) rmin, rmax = GR.adjustrange(minimum(r), maximum(r)) gr_polaraxes(rmin, rmax) - phi, r, = p[:x], p[:y] + phi, r = p[:x], p[:y] r = 0.5 * (r - rmin) / (rmax - rmin) n = length(r) x = zeros(n) From 42a175bd53bc3d7b88a8b5a452d4602e65ce349c Mon Sep 17 00:00:00 2001 From: Josef Heinen Date: Sat, 7 May 2016 12:45:09 +0200 Subject: [PATCH 2/4] Added support for :zlims keyword --- src/backends/gr.jl | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 6c4f93f9..be48f1ce 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -166,6 +166,25 @@ function gr_polaraxes(rmin, rmax) GR.restorestate() end +function gr_getzlims(d, zmin, zmax, adjust) + if haskey(d, :zlims) + if d[:zlims] != :auto + zlims = d[:zlims] + if zlims[1] != NaN + zmin = zlims[1] + end + if zlims[2] != NaN + zmax = zlims[2] + end + adjust = false + end + end + if adjust + zmin, zmax = GR.adjustrange(zmin, zmax) + end + zmin, zmax +end + function gr_display(plt::Plot{GRBackend}, clear=true, update=true, subplot=[0, 1, 0, 1]) d = plt.plotargs @@ -531,20 +550,21 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true, GR.cellarray(xmin, xmax, ymin, ymax, n, m, counts) GR.setviewport(viewport[2] + 0.02, viewport[2] + 0.05, viewport[3], viewport[4]) - GR.setspace(0, maximum(counts), 0, 90) + zmin, zmax = gr_getzlims(d, 0, maximum(counts), false) + GR.setspace(zmin, zmax, 0, 90) diag = sqrt((viewport[2] - viewport[1])^2 + (viewport[4] - viewport[3])^2) charheight = max(0.016 * diag, 0.01) GR.setcharheight(charheight) GR.colormap() elseif lt == :contour x, y, z = p[:x], p[:y], transpose_z(p, p[:z].surf, false) - zmin, zmax = minimum(z), maximum(z) + zmin, zmax = gr_getzlims(d, minimum(z), maximum(z), false) + GR.setspace(zmin, zmax, 0, 90) if typeof(p[:levels]) <: Array h = p[:levels] else h = linspace(zmin, zmax, p[:levels]) end - GR.setspace(zmin, zmax, 0, 90) GR.setcolormap(GR.COLORMAP_COOLWARM) GR.contour(x, y, h, reshape(z, length(x) * length(y)), 1000) GR.setviewport(viewport[2] + 0.02, viewport[2] + 0.05, @@ -559,7 +579,7 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true, GR.axes(0, ztick, xmax, zmin, 0, 1, 0.005) elseif lt in [:surface, :wireframe] x, y, z = p[:x], p[:y], transpose_z(p, p[:z].surf, false) - zmin, zmax = GR.adjustrange(minimum(z), maximum(z)) + zmin, zmax = gr_getzlims(d, minimum(z), maximum(z), true) GR.setspace(zmin, zmax, 40, 70) xtick = GR.tick(xmin, xmax) / 2 ytick = GR.tick(ymin, ymax) / 2 @@ -591,7 +611,7 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true, end elseif lt == :heatmap x, y, z = p[:x], p[:y], transpose_z(p, p[:z].surf, false) - zmin, zmax = GR.adjustrange(minimum(z), maximum(z)) + zmin, zmax = gr_getzlims(d, minimum(z), maximum(z), true) GR.setspace(zmin, zmax, 0, 90) GR.setcolormap(GR.COLORMAP_COOLWARM) z = reshape(z, length(x) * length(y)) @@ -603,7 +623,7 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true, end elseif lt in [:path3d, :scatter3d] x, y, z = p[:x], p[:y], p[:z] - zmin, zmax = GR.adjustrange(minimum(z), maximum(z)) + zmin, zmax = gr_getzlims(d, minimum(z), maximum(z), true) GR.setspace(zmin, zmax, 40, 70) xtick = GR.tick(xmin, xmax) / 2 ytick = GR.tick(ymin, ymax) / 2 From b6334176e4f5ab5a8753c3eb71d417831cee2158 Mon Sep 17 00:00:00 2001 From: Josef Heinen Date: Sat, 7 May 2016 13:24:11 +0200 Subject: [PATCH 3/4] Added support for :nbins keyword --- src/backends/gr.jl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index be48f1ce..f27a5e0d 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -260,7 +260,11 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true, elseif lt == :ohlc x, y = 1:size(p[:y], 1), p[:y] elseif lt in [:hist, :density] - x, y = Base.hist(p[:y]) + if haskey(p, :bins) + x, y = Base.hist(p[:y], p[:bins]) + else + x, y = Base.hist(p[:y]) + end elseif lt in [:hist2d, :hexbin] E = zeros(length(p[:x]),2) E[:,1] = p[:x] @@ -516,7 +520,11 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true, GR.fillrect(i-0.4, i+0.4, max(0, ymin), y[i]) end elseif lt in [:hist, :density] - h = Base.hist(p[:y]) + if haskey(p, :bins) + h = Base.hist(p[:y], p[:bins]) + else + h = Base.hist(p[:y]) + end x, y = float(collect(h[1])), float(h[2]) for i = 2:length(y) GR.setfillcolorind(gr_getcolorind(p[:fillcolor])) From 42d09a6d80c88ebe18d805c81a9f5faaac97173f Mon Sep 17 00:00:00 2001 From: Josef Heinen Date: Sun, 8 May 2016 10:55:27 +0200 Subject: [PATCH 4/4] Working on colormaps --- src/backends/gr.jl | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index f27a5e0d..c5024d25 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -427,6 +427,17 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true, for p in plt.seriesargs lt = p[:linetype] + if lt in (:hist2d, :hexbin, :contour, :surface, :wireframe, :heatmap) + if haskey(d, :color_palette) + ci = 1000 + for cv in d[:color_palette] + GR.setcolorrep(ci, cv.r, cv.g, cv.b) + ci += 1 + end + else + GR.setcolormap(GR.COLORMAP_COOLWARM) + end + end if get(d, :polar, false) lt = :polar end @@ -554,7 +565,6 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true, x, y, H = Base.hist2d(E, xbins, ybins) counts = round(Int32, 1000 + 255 * H / maximum(H)) n, m = size(counts) - GR.setcolormap(GR.COLORMAP_COOLWARM) GR.cellarray(xmin, xmax, ymin, ymax, n, m, counts) GR.setviewport(viewport[2] + 0.02, viewport[2] + 0.05, viewport[3], viewport[4]) @@ -573,7 +583,6 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true, else h = linspace(zmin, zmax, p[:levels]) end - GR.setcolormap(GR.COLORMAP_COOLWARM) GR.contour(x, y, h, reshape(z, length(x) * length(y)), 1000) GR.setviewport(viewport[2] + 0.02, viewport[2] + 0.05, viewport[3], viewport[4]) @@ -602,7 +611,6 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true, end z = reshape(z, length(x) * length(y)) if lt == :surface - GR.setcolormap(GR.COLORMAP_COOLWARM) GR.gr3.surface(x, y, z, GR.OPTION_COLORED_MESH) else GR.setfillcolorind(0) @@ -621,7 +629,6 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true, x, y, z = p[:x], p[:y], transpose_z(p, p[:z].surf, false) zmin, zmax = gr_getzlims(d, minimum(z), maximum(z), true) GR.setspace(zmin, zmax, 0, 90) - GR.setcolormap(GR.COLORMAP_COOLWARM) z = reshape(z, length(x) * length(y)) GR.surface(x, y, z, GR.OPTION_CELL_ARRAY) if cmap