From 0c5a9172abf12c9d1c005e231de8540762bef263 Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Fri, 6 Oct 2017 20:03:19 +0100 Subject: [PATCH 1/9] Added camera attribute processing. --- src/arg_desc.jl | 1 + src/args.jl | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/arg_desc.jl b/src/arg_desc.jl index ce24b8e0..53c8b51f 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -94,6 +94,7 @@ const _arg_desc = KW( :subplot_index => "Integer. Internal (not set by user). Specifies the index of this subplot in the Plot's `plt.subplot` list.", :colorbar_title => "String. Title of colorbar.", :framestyle => "Symbol. Style of the axes frame. Choose from $(_allFramestyles)", +:camera => "NTuple{2, Int(GR)/Real(Other)}. Sets the view angle (azimuthal, elevation) for 3D plots", # axis args :guide => "String. Axis guide (label).", diff --git a/src/args.jl b/src/args.jl index 3ea3efde..f36f2908 100644 --- a/src/args.jl +++ b/src/args.jl @@ -316,6 +316,7 @@ const _subplot_defaults = KW( :subplot_index => -1, :colorbar_title => "", :framestyle => :axes, + :camera => (30,30), ) const _axis_defaults = KW( @@ -532,6 +533,7 @@ add_aliases(:gridlinewidth, :gridwidth, :grid_linewidth, :grid_width, :gridlw, : add_aliases(:gridstyle, :grid_style, :gridlinestyle, :grid_linestyle, :grid_ls, :gridls) add_aliases(:framestyle, :frame_style, :frame, :axesstyle, :axes_style, :boxstyle, :box_style, :box, :borderstyle, :border_style, :border) add_aliases(:tick_direction, :tickdirection, :tick_dir, :tickdir, :tick_orientation, :tickorientation, :tick_or, :tickor) +add_aliases(:camera, :cam) # add all pluralized forms to the _keyAliases dict for arg in keys(_series_defaults) From 65a28e76e548e16938b3eb9f2602afb6b21cef6d Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Fri, 6 Oct 2017 20:06:39 +0100 Subject: [PATCH 2/9] Implemented camera attribute for GR. --- src/backends/gr.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 0d1d5a21..21d2c5db 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -34,6 +34,7 @@ const _gr_attr = merge_with_base_supported([ :arrow, :framestyle, :tick_direction, + :camera, ]) const _gr_seriestype = [ :path, :scatter, @@ -750,7 +751,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) isfinite(clims[1]) && (zmin = clims[1]) isfinite(clims[2]) && (zmax = clims[2]) end - GR.setspace(zmin, zmax, 35, 60) + GR.setspace(zmin, zmax, sp[:camera]...) xtick = GR.tick(xmin, xmax) / 2 ytick = GR.tick(ymin, ymax) / 2 ztick = GR.tick(zmin, zmax) / 2 From 94e79f1e4cfef52da891e8bc3d592ac28b14ba6b Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Fri, 6 Oct 2017 20:07:31 +0100 Subject: [PATCH 3/9] Implemented camera attribute for PyPlot. --- src/backends/pyplot.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 6ad195a2..e3b70eb9 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -35,6 +35,7 @@ const _pyplot_attr = merge_with_base_supported([ :stride, :framestyle, :tick_direction, + :camera, ]) const _pyplot_seriestype = [ :path, :steppre, :steppost, :shape, @@ -1104,6 +1105,13 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) ax[:set_aspect](isa(aratio, Symbol) ? string(aratio) : aratio, anchor = "C") end + #camera/view angle + if is3d(sp) + #convert azimuthal to match GR behaviour + #view_init(elevation, azimuthal) so reverse :camera args + ax[:view_init]((sp[:camera].-(90,0))[end:-1:1]...) + end + # legend py_add_legend(plt, sp, ax) From 0fb1a0ed6bfc579f7577aae59de59819bac8e104 Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Fri, 6 Oct 2017 20:07:48 +0100 Subject: [PATCH 4/9] Implemented camera attribute for PGFPlots. --- src/backends/pgfplots.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index b54d8aa0..a5f1a1b0 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -33,6 +33,7 @@ const _pgfplots_attr = merge_with_base_supported([ # :match_dimensions, :tick_direction, :framestyle, + :camera, ]) const _pgfplots_seriestype = [:path, :path3d, :scatter, :steppre, :stepmid, :steppost, :histogram2d, :ysticks, :xsticks, :contour, :shape] const _pgfplots_style = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] @@ -380,6 +381,11 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend}) kw[:legendPos] = _pgfplots_legend_pos[legpos] end + if is3d(sp) + azim, elev = sp[:camera] + kw[:view] = "{$(azim)}{$(elev)}" + end + axisf = PGFPlots.Axis if sp[:projection] == :polar axisf = PGFPlots.PolarAxis From ccb3cadd2a9e9fa7a9d372bbf21c79542bcc916c Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Fri, 6 Oct 2017 20:09:39 +0100 Subject: [PATCH 5/9] Implemented camera attribute for Plotly/PlotlyJS. --- src/backends/plotly.jl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index b3c40158..c67511d2 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -35,6 +35,7 @@ const _plotly_attr = merge_with_base_supported([ :clims, :framestyle, :tick_direction, + :camera, ]) const _plotly_seriestype = [ @@ -324,10 +325,21 @@ function plotly_layout(plt::Plot) # if any(is3d, seriesargs) if is3d(sp) + azim = sp[:camera][1] - 90 #convert azimuthal to match GR behaviour + theta = 90 - sp[:camera][2] #spherical coordinate angle from z axis d_out[:scene] = KW( Symbol("xaxis$spidx") => plotly_axis(sp[:xaxis], sp), Symbol("yaxis$spidx") => plotly_axis(sp[:yaxis], sp), Symbol("zaxis$spidx") => plotly_axis(sp[:zaxis], sp), + + #2.6 multiplier set camera eye such that whole plot can be seen + :camera => KW( + :eye => KW( + :x => cosd(azim)*sind(theta)*2.6, + :y => sind(azim)*sind(theta)*2.6, + :z => cosd(theta)*2.6, + ), + ), ) else d_out[Symbol("xaxis$spidx")] = plotly_axis(sp[:xaxis], sp) From cf6f7035b6d9badc5e879ecf2c27d8a5dcd42d08 Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Sat, 7 Oct 2017 20:05:05 +0100 Subject: [PATCH 6/9] Added extra :camera aliases. --- src/args.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/args.jl b/src/args.jl index f36f2908..505b1d74 100644 --- a/src/args.jl +++ b/src/args.jl @@ -533,7 +533,7 @@ add_aliases(:gridlinewidth, :gridwidth, :grid_linewidth, :grid_width, :gridlw, : add_aliases(:gridstyle, :grid_style, :gridlinestyle, :grid_linestyle, :grid_ls, :gridls) add_aliases(:framestyle, :frame_style, :frame, :axesstyle, :axes_style, :boxstyle, :box_style, :box, :borderstyle, :border_style, :border) add_aliases(:tick_direction, :tickdirection, :tick_dir, :tickdir, :tick_orientation, :tickorientation, :tick_or, :tickor) -add_aliases(:camera, :cam) +add_aliases(:camera, :cam, :view, :viewangle, :view_angle) # add all pluralized forms to the _keyAliases dict for arg in keys(_series_defaults) From f4bc2e06490fadb5bc5957af3bc85bc05fdc87ff Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Sat, 7 Oct 2017 20:05:53 +0100 Subject: [PATCH 7/9] Convert :camera attribute input for GR. --- src/arg_desc.jl | 2 +- src/backends/gr.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arg_desc.jl b/src/arg_desc.jl index 53c8b51f..f0df3e92 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -94,7 +94,7 @@ const _arg_desc = KW( :subplot_index => "Integer. Internal (not set by user). Specifies the index of this subplot in the Plot's `plt.subplot` list.", :colorbar_title => "String. Title of colorbar.", :framestyle => "Symbol. Style of the axes frame. Choose from $(_allFramestyles)", -:camera => "NTuple{2, Int(GR)/Real(Other)}. Sets the view angle (azimuthal, elevation) for 3D plots", +:camera => "NTuple{2, Real}. Sets the view angle (azimuthal, elevation) for 3D plots", # axis args :guide => "String. Axis guide (label).", diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 21d2c5db..01b9d6e6 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -751,7 +751,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) isfinite(clims[1]) && (zmin = clims[1]) isfinite(clims[2]) && (zmax = clims[2]) end - GR.setspace(zmin, zmax, sp[:camera]...) + GR.setspace(zmin, zmax, map(Int,map(round,sp[:camera]))...) xtick = GR.tick(xmin, xmax) / 2 ytick = GR.tick(ymin, ymax) / 2 ztick = GR.tick(zmin, zmax) / 2 From f8576c71350ccc43fb36cdbbfd431c37d2ff4973 Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Mon, 9 Oct 2017 11:33:24 +0100 Subject: [PATCH 8/9] Remove :view alias for :camera attribute. --- src/args.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/args.jl b/src/args.jl index 505b1d74..7632b5bf 100644 --- a/src/args.jl +++ b/src/args.jl @@ -533,7 +533,7 @@ add_aliases(:gridlinewidth, :gridwidth, :grid_linewidth, :grid_width, :gridlw, : add_aliases(:gridstyle, :grid_style, :gridlinestyle, :grid_linestyle, :grid_ls, :gridls) add_aliases(:framestyle, :frame_style, :frame, :axesstyle, :axes_style, :boxstyle, :box_style, :box, :borderstyle, :border_style, :border) add_aliases(:tick_direction, :tickdirection, :tick_dir, :tickdir, :tick_orientation, :tickorientation, :tick_or, :tickor) -add_aliases(:camera, :cam, :view, :viewangle, :view_angle) +add_aliases(:camera, :cam, :viewangle, :view_angle) # add all pluralized forms to the _keyAliases dict for arg in keys(_series_defaults) From 6df2bc2790c8018db6eaf731ef08654199c29d64 Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Mon, 9 Oct 2017 11:40:04 +0100 Subject: [PATCH 9/9] Clarify gr.jl setspace() rounding syntax. --- src/backends/gr.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 01b9d6e6..5430f53b 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -751,7 +751,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) isfinite(clims[1]) && (zmin = clims[1]) isfinite(clims[2]) && (zmax = clims[2]) end - GR.setspace(zmin, zmax, map(Int,map(round,sp[:camera]))...) + GR.setspace(zmin, zmax, round.(Int, sp[:camera])...) xtick = GR.tick(xmin, xmax) / 2 ytick = GR.tick(ymin, ymax) / 2 ztick = GR.tick(zmin, zmax) / 2