diff --git a/Project.toml b/Project.toml index 3040db461..9cef1f37e 100644 --- a/Project.toml +++ b/Project.toml @@ -80,7 +80,7 @@ JLFzf = "0.1" PrecompileTools = "1" PGFPlotsX = "1" Unzip = "0.1 - 0.2" -PythonPlot = "1" +PythonPlot = "1 - 1.0.2" UnitfulLatexify = "1" RecipesPipeline = "1" LaTeXStrings = "1" diff --git a/ext/PlotsGastonExt/gaston.jl b/ext/PlotsGastonExt/gaston.jl index 6a3916973..c6eeb3878 100644 --- a/ext/PlotsGastonExt/gaston.jl +++ b/ext/PlotsGastonExt/gaston.jl @@ -557,7 +557,7 @@ function gaston_parse_axes_attrs( tmin, tmax = axis_limits(sp, :x, false, false) rmin, rmax = axis_limits(sp, :y, false, false) rticks = get_ticks(sp, :y) - gaston_ticks = if (ttype = ticksType(rticks)) === :ticks + gaston_ticks = if (ttype = ticks_type(rticks)) === :ticks string.(rticks) elseif ttype === :ticks_and_labels ["'$l' $t" for (t, l) in zip(rticks...)] @@ -594,7 +594,7 @@ function gaston_set_ticks!(axesconf, ticks, letter, I, maj_min, add) push!(axesconf, "unset $(maj_min)$(letter)tics") return end - gaston_ticks = if (ttype = ticksType(ticks)) === :ticks + gaston_ticks = if (ttype = ticks_type(ticks)) === :ticks tics = gaston_fix_ticks_overflow(ticks) if maj_min == "m" map(t -> "'' $t 1", tics) # see gnuplot manual 'Mxtics' diff --git a/ext/PlotsInspectDR/inspectdr.jl b/ext/PlotsInspectDR/inspectdr.jl index 07a435fa0..b80b71952 100644 --- a/ext/PlotsInspectDR/inspectdr.jl +++ b/ext/PlotsInspectDR/inspectdr.jl @@ -96,7 +96,7 @@ function _inspectdr_getaxisticks(ticks, gridlines, xfrm) TickCustom = InspectDR.TickCustom _xfrm(coord) = InspectDR.axis2aloc(Float64(coord), xfrm.spec) #Ensure Float64 - in case - ttype = ticksType(ticks) + ttype = ticks_type(ticks) if ticks === :native # keep current elseif ttype === :ticks_and_labels diff --git a/ext/PlotsPlotlyJSExt/PlotsPlotlyJSExt.jl b/ext/PlotsPlotlyJSExt/PlotsPlotlyJSExt.jl index 149b2a942..8abde206f 100644 --- a/ext/PlotsPlotlyJSExt/PlotsPlotlyJSExt.jl +++ b/ext/PlotsPlotlyJSExt/PlotsPlotlyJSExt.jl @@ -1,8 +1,10 @@ module PlotsPlotlyJSExt using PlotlyJS: PlotlyJS -using Plots: Plots, Plot, plotly_show_js, isplotnull, current -import Plots: _show, _display, closeall +using Plots.Commons +using Plots.Plotly +using Plots.PlotsPlots +import Plots: _show, _display, closeall, current, isplotnull include("initialization.jl") include("plotlyjs.jl") diff --git a/ext/PlotsPlotlyJSExt/initialization.jl b/ext/PlotsPlotlyJSExt/initialization.jl index bca23ecb5..973c99656 100644 --- a/ext/PlotsPlotlyJSExt/initialization.jl +++ b/ext/PlotsPlotlyJSExt/initialization.jl @@ -14,7 +14,7 @@ function __init__() @info "Initializing $package_str backend in Plots; run `$str()` to activate it." Plots._backendType[sym] = get_concrete_backend() Plots._backendSymbol[T] = sym - + push!(Plots._initialized_backends, sym) @@ -25,11 +25,11 @@ end Plots.backend_name(::T) = sym Plots.backend_package_name(::T) = Plots.backend_package_name(sym) -const _plotlyjs_attrs = Plots._plotly_attrs -const _plotlyjs_seriestypes = Plots._plotly_seriestypes -const _plotlyjs_styles = Plots._plotly_styles -const _plotlyjs_markers = Plots._plotly_markers -const _plotlyjs_scales = Plots._plotly_scales +const _plotlyjs_attrs = Plots.Plotly._plotly_attrs +const _plotlyjs_seriestypes = Plots.Plotly._plotly_seriestypes +const _plotlyjs_styles = Plots.Plotly._plotly_styles +const _plotlyjs_markers = Plots.Plotly._plotly_markers +const _plotlyjs_scales = Plots.Plotly._plotly_scales # ----------------------------------------------------------------------------- # Overload (dispatch) abstract `is_xxx_supported` and `supported_xxxs` methods diff --git a/ext/PlotsPythonPlotExt/PlotsPythonPlotExt.jl b/ext/PlotsPythonPlotExt/PlotsPythonPlotExt.jl index 1fdc071d1..079210618 100644 --- a/ext/PlotsPythonPlotExt/PlotsPythonPlotExt.jl +++ b/ext/PlotsPythonPlotExt/PlotsPythonPlotExt.jl @@ -61,7 +61,7 @@ using Plots: isscalar, isvector, supported_scales, - ticksType, + ticks_type, legend_angle, legend_anchor_index, legend_pos_from_angle, diff --git a/ext/PlotsPythonPlotExt/pythonplot.jl b/ext/PlotsPythonPlotExt/pythonplot.jl index 7996e1bbc..000dccc97 100644 --- a/ext/PlotsPythonPlotExt/pythonplot.jl +++ b/ext/PlotsPythonPlotExt/pythonplot.jl @@ -751,7 +751,7 @@ function _py_set_ticks(sp, ax, ticks, letter) return end - tick_values, tick_labels = if (ttype = ticksType(ticks)) === :ticks + tick_values, tick_labels = if (ttype = ticks_type(ticks)) === :ticks ticks, [] elseif ttype === :ticks_and_labels ticks @@ -1057,7 +1057,7 @@ function _before_layout_calcs(plt::Plot{PythonPlotBackend}) ticks = framestyle === :none ? nothing : get_ticks(sp, axis) has_major_ticks = ticks !== :none && ticks !== nothing && ticks !== false - has_major_ticks &= if (ttype = ticksType(ticks)) === :ticks + has_major_ticks &= if (ttype = ticks_type(ticks)) === :ticks length(ticks) > 0 elseif ttype === :ticks_and_labels tcs, labs = ticks diff --git a/src/Commons/Commons.jl b/src/Commons/Commons.jl index ae86629a6..e0442679b 100644 --- a/src/Commons/Commons.jl +++ b/src/Commons/Commons.jl @@ -2,7 +2,7 @@ module Commons export AVec, AMat, KW, AKW, TicksArgs -export PLOTS_SEED +export Plots, PLOTS_SEED export _haligns, _valigns, _cbar_width # Functions export get_subplot, @@ -122,7 +122,7 @@ all_alphas(arg) = true_or_all_true( arg, ) all_reals(arg) = true_or_all_true(a -> typeof(a) <: Real, arg) -allFunctions(arg) = true_or_all_true(a -> isa(a, Function), arg) +all_functionss(arg) = true_or_all_true(a -> isa(a, Function), arg) # --------------------------------------------------------------- include("attrs.jl") diff --git a/src/Commons/attrs.jl b/src/Commons/attrs.jl index 19c693597..551d9d047 100644 --- a/src/Commons/attrs.jl +++ b/src/Commons/attrs.jl @@ -860,7 +860,7 @@ function process_fill_attr(plotattributes::AKW, arg) plotattributes[:fillrange] = arg ? 0 : nothing # fillrange function - elseif allFunctions(arg) + elseif all_functionss(arg) plotattributes[:fillrange] = arg # fillalpha diff --git a/src/Plots.jl b/src/Plots.jl index d5c9fa874..fc5ebd9dc 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -198,6 +198,7 @@ include("output.jl") include("shorthands.jl") include("backends/web.jl") include("backends/plotly.jl") +using .Plotly include("init.jl") include("users.jl") diff --git a/src/Strokes.jl b/src/Strokes.jl index b08a57e45..8398a7896 100644 --- a/src/Strokes.jl +++ b/src/Strokes.jl @@ -2,7 +2,7 @@ module Strokes export stroke, brush, Stroke, Brush using Plots.Colors: Colorant -using Plots.Commons: allAlphas, allReals, allStyles +using Plots.Commons: all_alphas, all_reals, all_styles struct Stroke width color @@ -24,7 +24,7 @@ function stroke(args...; alpha = nothing) T = typeof(arg) # if arg in _all_styles - if allStyles(arg) + if all_styles(arg) style = arg elseif T <: Colorant color = arg @@ -33,9 +33,9 @@ function stroke(args...; alpha = nothing) color = parse(Colorant, string(arg)) catch end - elseif allAlphas(arg) + elseif all_alphas(arg) alpha = arg - elseif allReals(arg) + elseif all_reals(arg) width = arg else @warn "Unused stroke arg: $arg ($(typeof(arg)))" @@ -65,9 +65,9 @@ function brush(args...; alpha = nothing) color = parse(Colorant, string(arg)) catch end - elseif allAlphas(arg) + elseif all_alphas(arg) alpha = arg - elseif allReals(arg) + elseif all_reals(arg) size = arg else @warn "Unused brush arg: $arg ($(typeof(arg)))" diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index ae2645bdc..d4b7a4b7d 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -1,17 +1,28 @@ # https://plot.ly/javascript/getting-started +module Plotly -_plotly_framestyle(style::Symbol) = - if style in (:box, :axes, :zerolines, :grid, :none) - style - else - default_style = get((semi = :box, origin = :zerolines), style, :axes) - @warn "Framestyle :$style is not supported by Plotly and PlotlyJS. :$default_style was chosen instead." - default_style - end - -# -------------------------------------------------------------------------------------- +export PlotlyBackend, plotly_show_js, plotly_series, plotly_layout, embeddable_html using UUIDs +using Statistics: mean +using Plots: bbox_to_pcts, labelfunc_tex, is_2tuple, ticks_type, recursive_merge +using Plots.Annotations +using Plots.Axes +using Plots.Colorbars +using Plots.Colors: Colorant +using Plots.Commons +using Plots.Fonts +using Plots.Fonts: PlotText +using Plots.PlotMeasures +using Plots.PlotsPlots +using Plots.PlotsSeries +using Plots.PlotUtils: PlotUtils, ColorGradient, rgba_string, rgb_string +using Plots.RecipesPipeline: RecipesPipeline +using Plots.Subplots +using Plots.Surfaces +using Plots.Ticks +import Plots: labelfunc, _show, _display, default_output_format +import Plots: backend_name, backend_package_name struct PlotlyBackend <: Plots.AbstractBackend end Plots._backendType[:plotly] = PlotlyBackend @@ -169,7 +180,7 @@ const _plotly_markers = [ ] const _plotly_scales = [:identity, :log10] -defaultOutputFormat(plt::Plot{Plots.PlotlyBackend}) = "html" +default_output_format(plt::Plot{PlotlyBackend}) = "html" for s in (:attr, :seriestype, :marker, :style, :scale) f1 = Symbol("is_", s, "_supported") @@ -192,6 +203,15 @@ function labelfunc(scale::Symbol, backend::PlotlyBackend) end end +_plotly_framestyle(style::Symbol) = + if style in (:box, :axes, :zerolines, :grid, :none) + style + else + default_style = get((semi = :box, origin = :zerolines), style, :axes) + @warn "Framestyle :$style is not supported by Plotly and PlotlyJS. :$default_style was chosen instead." + default_style + end + plotly_font(font::Font, color = font.color) = KW( :family => font.family, :size => round(Int, 1.4font.pointsize), @@ -326,7 +346,7 @@ function plotly_axis(axis, sp, anchor = nothing, domain = nothing) # ticks if axis[:ticks] !== :native ticks = get_ticks(sp, axis) - ttype = ticksType(ticks) + ttype = ticks_type(ticks) if ttype === :ticks ax[:tickmode] = "array" ax[:tickvals] = ticks @@ -1301,3 +1321,4 @@ _show(io::IO, ::MIME"application/vnd.plotly.v1+json", plot::Plot{PlotlyBackend}) _show(io::IO, ::MIME"text/html", plt::Plot{PlotlyBackend}) = write(io, embeddable_html(plt)) _display(plt::Plot{PlotlyBackend}) = standalone_html_window(plt) +end # module diff --git a/src/output.jl b/src/output.jl index 3e319bb78..b63f18f90 100644 --- a/src/output.jl +++ b/src/output.jl @@ -1,6 +1,6 @@ struct PlotsDisplay <: AbstractDisplay end -defaultOutputFormat(plt::Plot) = "png" +default_output_format(plt::Plot) = "png" function png(plt::Plot, fn) fn = addExtension(fn, "png") @@ -142,7 +142,7 @@ function savefig(plt::Plot, fn) # fn might be an `AbstractString` or an `Abstrac # get the extension _, ext = splitext(fn) ext = chop(ext, head = 1, tail = 0) - isempty(ext) && (ext = defaultOutputFormat(plt)) + isempty(ext) && (ext = default_output_format(plt)) # save it if haskey(_savemap, ext) diff --git a/src/utils.jl b/src/utils.jl index fe16954e5..6774a35dc 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -282,10 +282,10 @@ isscalar(::Any) = false is_2tuple(v) = typeof(v) <: Tuple && length(v) == 2 -ticksType(ticks::AVec{<:Real}) = :ticks -ticksType(ticks::AVec{<:AbstractString}) = :labels -ticksType(ticks::Tuple{<:Union{AVec,Tuple},<:Union{AVec,Tuple}}) = :ticks_and_labels -ticksType(ticks) = :invalid +ticks_type(ticks::AVec{<:Real}) = :ticks +ticks_type(ticks::AVec{<:AbstractString}) = :labels +ticks_type(ticks::Tuple{<:Union{AVec,Tuple},<:Union{AVec,Tuple}}) = :ticks_and_labels +ticks_type(ticks) = :invalid limsType(lims::Tuple{<:Real,<:Real}) = :limits limsType(lims::Symbol) = lims === :auto ? :auto : :invalid diff --git a/test/test_output.jl b/test/test_output.jl index 733dbbf4b..75cacad06 100644 --- a/test/test_output.jl +++ b/test/test_output.jl @@ -30,7 +30,7 @@ macro test_save(fmt) end with(:gr) do - @test Plots.defaultOutputFormat(plot()) == "png" + @test Plots.default_output_format(plot()) == "png" @test Plots.addExtension("foo", "bar") == "foo.bar" @test_save :png diff --git a/test/test_utils.jl b/test/test_utils.jl index 12be708b4..e093b7b98 100644 --- a/test/test_utils.jl +++ b/test/test_utils.jl @@ -116,11 +116,11 @@ @test Plots.limsType(:auto) === :auto @test Plots.limsType(NaN) === :invalid - @test Plots.ticksType([1, 2]) === :ticks - @test Plots.ticksType(["1", "2"]) === :labels - @test Plots.ticksType(([1, 2], ["1", "2"])) === :ticks_and_labels - @test Plots.ticksType(((1, 2), ("1", "2"))) === :ticks_and_labels - @test Plots.ticksType(:undefined) === :invalid + @test Plots.ticks_type([1, 2]) === :ticks + @test Plots.ticks_type(["1", "2"]) === :labels + @test Plots.ticks_type(([1, 2], ["1", "2"])) === :ticks_and_labels + @test Plots.ticks_type(((1, 2), ("1", "2"))) === :ticks_and_labels + @test Plots.ticks_type(:undefined) === :invalid pl = plot(1:2, 1:2, 1:2, proj_type = :ortho) @test Plots.isortho(first(pl.subplots))