From 36cd80e9d04a2b55398c221c3cd91e1dc204a622 Mon Sep 17 00:00:00 2001 From: Naoki Saito Date: Sun, 8 Jan 2017 14:17:38 -0800 Subject: [PATCH] An attempt to add the surfacecolor attribute to the surface function using plotly(js) --- src/arg_desc.jl | 1 + src/args.jl | 2 ++ src/backends/plotly.jl | 4 ++-- test/surfacetest.jl | 12 ++++++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 test/surfacetest.jl diff --git a/src/arg_desc.jl b/src/arg_desc.jl index b4503c1e..e1982ba6 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -29,6 +29,7 @@ const _arg_desc = KW( :z => "Various. Input data. Third Dimension. May be wrapped by a `Surface` for surface and heatmap types.", :marker_z => "AbstractVector, Function `f(x,y,z) -> z_value`, or nothing. z-values for each series data point, which correspond to the color to be used from a markercolor gradient.", :line_z => "AbstractVector, Function `f(x,y,z) -> z_value`, or nothing. z-values for each series line segment, which correspond to the color to be used from a linecolor gradient. Note that for N points, only the first N-1 values are used (one per line-segment).", +:surfacecolor => "Matrix{Float64} of the same size as z matrix, which specifies the color of the 3D surface; the default value is `nothing`.", :levels => "Integer, NTuple{2,Integer}. Number of levels (or x-levels/y-levels) for a contour type.", :orientation => "Symbol. Horizontal or vertical orientation for bar types. Values `:h`, `:hor`, `:horizontal` correspond to horizontal (sideways, anchored to y-axis), and `:v`, `:vert`, and `:vertical` correspond to vertical (the default).", :bar_position => "Symbol. Choose from `:overlay` (default), `:stack`. (warning: May not be implemented fully)", diff --git a/src/args.jl b/src/args.jl index 119dd125..479912e3 100644 --- a/src/args.jl +++ b/src/args.jl @@ -189,6 +189,7 @@ const _series_defaults = KW( :marker_z => nothing, # value for color scale :line_z => nothing, :levels => 15, + :surfacecolor => nothing, :orientation => :vertical, :bar_position => :overlay, # for bar plots and histograms: could also be stack (stack up) or dodge (side by side) :bar_width => nothing, @@ -431,6 +432,7 @@ add_aliases(:zguide, :zlabel, :zlab, :zl) add_aliases(:zlims, :zlim, :zlimit, :zlimits) add_aliases(:zticks, :ztick) add_aliases(:zrotation, :zrot, :zr) +add_aliases(:surfacecolor, :surfacecolour, :sc, :surfcolor, :surfcolour) add_aliases(:legend, :leg, :key) add_aliases(:colorbar, :cb, :cbar, :colorkey) add_aliases(:clims, :clim, :cbarlims, :cbar_lims, :climits, :color_limits) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index a70ddf60..8905ec33 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -20,7 +20,7 @@ const _plotly_attr = merge_with_base_supported([ :guide, :lims, :ticks, :scale, :flip, :rotation, :tickfont, :guidefont, :legendfont, :grid, :legend, :colorbar, - :marker_z, :levels, + :marker_z, :surfacecolor, :levels, :ribbon, :quiver, :orientation, # :overwrite_figure, @@ -432,7 +432,7 @@ function plotly_series(plt::Plot, series::Series) # for surface types, set the data if st in (:heatmap, :contour, :surface, :wireframe) - for letter in [:x,:y,:z] + for letter in [:x,:y,:z,:surfacecolor] d_out[letter] = plotly_surface_data(series, series[letter]) end end diff --git a/test/surfacetest.jl b/test/surfacetest.jl new file mode 100644 index 00000000..6779183b --- /dev/null +++ b/test/surfacetest.jl @@ -0,0 +1,12 @@ +module SurfacePlotsTests +m=32; n=5; +r = (0:m)/m +theta = reshape(pi*(-n*m:n*m)/m, 1, 2*n*m+1) +z = r * exp(im*theta) +s = r.^(1/n) * exp(im*theta/n) +x = real(z) +y = imag(z) +u = real(s) +v = imag(s) +surface(x,y,u,surfacecolor=randn(size(v))) +end