From 7264c01b85dccf1d5e4c45c3a4e1bb374f2c7968 Mon Sep 17 00:00:00 2001 From: Josef Heinen Date: Wed, 16 Mar 2016 18:05:20 +0100 Subject: [PATCH] Added :heatmap linetype --- src/backends/gr.jl | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index cc3f22b8..6b07f5a1 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -145,6 +145,7 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true, cmap = false axes_2d = true grid_flag = get(d, :grid, true) + outside_ticks = false for axis = 1:2 xmin = ymin = typemax(Float64) @@ -160,7 +161,7 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true, x, y = 1:size(p[:y], 1), p[:y] elseif p[:linetype] in [:hist, :density] x, y = Base.hist(p[:y]) - elseif p[:linetype] in [:heatmap, :hexbin] + elseif p[:linetype] in [:hist2d, :hexbin] E = zeros(length(p[:x]),2) E[:,1] = p[:x] E[:,2] = p[:y] @@ -176,12 +177,15 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true, xmin, xmax, ymin, ymax = 0, 1, 0, 1 x, y = p[:x], p[:y] else - if p[:linetype] in [:contour, :surface] + if p[:linetype] in [:contour, :surface, :heatmap] cmap = true end if p[:linetype] in [:surface, :wireframe, :path3d, :scatter3d] axes_2d = false end + if p[:linetype] == :heatmap + outside_ticks = true + end x, y = p[:x], p[:y] end if p[:linetype] != :pie @@ -267,6 +271,9 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true, GR.setlinewidth(1) GR.setlinecolorind(fg) ticksize = 0.0075 * diag + if outside_ticks + ticksize = -ticksize + end if grid_flag && fg == 1 GR.grid(xtick, ytick, 0, 0, majorx, majory) end @@ -423,7 +430,7 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true, GR.polyline([xy, xy], [ymin, ymax]) end end - elseif p[:linetype] in [:heatmap, :hexbin] + elseif p[:linetype] in [:hist2d, :hexbin] E = zeros(length(p[:x]),2) E[:,1] = p[:x] E[:,2] = p[:y] @@ -497,6 +504,18 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true, viewport[3], viewport[4]) GR.colormap() end + elseif p[:linetype] == :heatmap + x, y, z = p[:x], p[:y], p[:z].surf + zmin, zmax = GR.adjustrange(minimum(z), maximum(z)) + 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 + GR.setviewport(viewport[2] + 0.02, viewport[2] + 0.05, + viewport[3], viewport[4]) + GR.colormap() + end elseif p[:linetype] in [:path3d, :scatter3d] x, y, z = p[:x], p[:y], p[:z] zmin, zmax = GR.adjustrange(minimum(z), maximum(z))