JuliaPlots / PlotlyJS.jl

Julia library for plotting with plotly.js
Other
413 stars 77 forks source link

cannot create subplots of pie #468

Open nesteiner opened 1 year ago

nesteiner commented 1 year ago

Describe the bug I have such code

using StatsBase, PlotlyJS, DataFrames
let nums = rand(1:10, 100)
  cm = countmap(nums)
  xs = collect(keys(cm))
  ys = collect(values(cm))

  df = DataFrame(xs = xs, ys = ys)

  p = PlotlyJS.pie(df, values = :ys, textposition = "inside")

  sp = make_subplots(rows = 1, cols = 2)
  add_trace!(sp, p, row = 1, col = 1)
  add_trace!(sp, p, row = 1, col = 2)
  sp
end

what I expect is that there are two pie plots in the figure, however there is only one pie plot

image

Version info

Please provide the following:

  1. output of julia command versioninfo()
    Julia Version 1.9.1
    Commit 147bdf428cd (2023-06-07 08:27 UTC)
    Platform Info:
    OS: Linux (x86_64-linux-gnu)
    CPU: 8 × 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
    WORD_SIZE: 64
    LIBM: libopenlibm
    LLVM: libLLVM-14.0.6 (ORCJIT, tigerlake)
    Threads: 5 on 8 virtual cores
    Environment:
    JULIA_EDITOR = code
    JULIA_NUM_THREADS = 
    JULIA_PKG_SERVER = https://mirrors.bfsu.edu.cn/julia
  2. Output running the following in Julia 0.7 or greater: using Pkg; pkg"status" (if you are on Julia 0.6 or earlier run Pkg.status())
    [aaaa29a8] Clustering v0.15.3
    [a81c6b42] Compose v0.9.5
    [a93c6f00] DataFrames v1.5.0
    [0c46a032] DifferentialEquations v7.8.0
    [a2cc645c] GraphPlot v0.5.2
    [86223c79] Graphs v1.8.0
    [87dc4568] HiGHS v1.5.2
    [b6b21f68] Ipopt v1.4.1
    [4076af6c] JuMP v1.12.0
    [54119dfa] MLJXGBoostInterface v0.3.8
    ⌅ [961ee093] ModelingToolkit v8.59.1
    [f0f68f2c] PlotlyJS v0.18.10
    [91a5bcdd] Plots v1.38.16
    [c3e4b0f8] Pluto v0.19.26
    [78aadeae] SymbolicNumericIntegration v1.1.0
    [0c5d862f] Symbolics v5.5.0
    [009559a3] XGBoost v2.3.0
    [fdbf4ff8] XLSX v0.9.0
    [e88e6eb3] Zygote v0.6.62
empet commented 1 year ago

When you define the plot, sp, you should set the specs, i.e. the type of trace for each subplot cell. See also: https://github.com/sglyon/PlotlyBase.jl/blob/master/src/subplot_utils.jl#L155.

let nums = rand(1:10, 100)
  cm = countmap(nums)
  xs = collect(keys(cm))
  ys = collect(values(cm))

  df = DataFrame(xs = xs, ys = ys)

  p = PlotlyJS.pie(df, values = :ys, textposition = "inside")

  sp = make_subplots(rows = 1, cols = 2, specs =[Spec(kind="pie") for i=1:1, j in 1:2])
  add_trace!(sp, p, row = 1, col = 1)
  add_trace!(sp, p, row = 1, col = 2)
  sp
end
nesteiner commented 1 year ago

oh, thank you, it's my fault