Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Files saved with savefig not display Legend Group Titles #456

Open
Straehlc opened this issue Dec 15, 2022 · 4 comments
Open

Files saved with savefig not display Legend Group Titles #456

Straehlc opened this issue Dec 15, 2022 · 4 comments

Comments

@Straehlc
Copy link

Describe the bug
When saving a plot which contains legend groups and legend group titles, the legend group title go missing in the output file depending on file type. PNG and PDF have no legend group titles, while the HTML retains those.
While saving a PNG from the html does work and the legend group titles are visible.
Code I used:
`
using PlotlyJS

p = Plot()
add_trace!(p,scatter(x=1:100,y=rand(100),name="1",legendgroup="group",legendgrouptitle_text="First Group"))
add_trace!(p,scatter(x=1:100,y=rand(100),name="1",legendgroup="group"))
add_trace!(p,scatter(x=1:100,y=rand(100),name="1",legendgroup="group2",legendgrouptitle_text="Second Group"))

savefig(p,"test.html")
savefig(p,"test.png")
`

Version info
On Windows 10
Please provide the following:

  1. output of julia command versioninfo()

Julia Version 1.8.2
Commit 36034abf26 (2022-09-29 15:21 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: 8 × Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-13.0.1 (ORCJIT, skylake)
Threads: 1 on 8 virtual cores
Environment:
JULIA_EDITOR = code
JULIA_NUM_THREADS =

  1. 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())

[336ed68f] CSV v0.10.7
[a93c6f00] DataFrames v1.4.4
[7a1cc6ca] FFTW v1.5.0
[38e38edf] GLM v1.8.1
[7073ff75] IJulia v1.23.3
[23992714] MAT v0.10.3
[f0f68f2c] PlotlyJS v0.18.10
[91a5bcdd] Plots v1.36.6
[92933f4c] ProgressMeter v1.7.2
[5bab7191] SPICE v0.2.3

Directly save to PNG using savefig:
failed
Saved from html:
from_html

@pawbz
Copy link

pawbz commented Jan 3, 2023

It would be nice if this could be resolved. Facing the same issue. The legendgrouptitle_text is replaced with Aa before saving as e.g., PDF.

@qdddddd
Copy link

qdddddd commented Mar 9, 2023

Same issue here saving as SVG.

@nrummel
Copy link

nrummel commented Dec 13, 2024

I also am dealing with this issue is there a work around?

@nrummel
Copy link

nrummel commented Dec 13, 2024

Description of Bug

I wanted to make a plot that has lots of traces, but they can be grouped. The plotlyjs package allows for these "legendgroups" to be separated and labeled in the legend with a trace attribute called "legendgrouptitle". Unfortunately when I went to save, the legend group title disappears from the plot.

Resolution

What was happening in the kaleido process is that an old version of plotlyjs is being loaded by default. By passing the version explicitly we can resolve the issue. This is a problem on the ploly side because the default version of plotlyjs is set to 1.58.x and the latex is 2.53.x.

Simple Example

using PlotlyKaleido: savefig, start

using PlotlyJS: plot, scatter, display, Layout, attr

p = plot(
    scatter(
        x=1:5, 
        y=rand(5),
        name="Trace Name",
        legendgrouptitle=attr(text="Legend Group Title"),
        legendgroup=1,
    ),
    Layout(showlegend=true)
)
display(p.plot)
savefig(p, joinpath(@__DIR__, "tmp.png"))
# re-start kaleido with the newer plotlyjs version
start(plotly_version = "2.35.2", mathjax = true,) 

savefig(p, joinpath(@__DIR__, "tmp_new.png"))

Output

Below is a screen shot of the display where the legendgrouptitle is working properly.
Screenshot 2024-12-13 at 2 42 45 PM
Below is the saved png that no longer has the legendgrouptitle because the wrong version of plotlyjs is loaded
tmp
Below is the saved png that has the legendgrouptitle because the correct version of plotlyjs is loaded
tmp_new

Version info

Julia Version 1.11.2
Commit 5e9a32e7af2 (2024-12-01 20:02 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin24.0.0)
  CPU: 12 × Apple M3 Pro
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, apple-m2)
Threads: 16 default, 0 interactive, 6 GC (on 6 virtual cores)
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 16

Package Status

Status `~/scratch/wendy/plotlybug/Project.toml`
  [f0f68f2c] PlotlyJS v0.18.15
  [f2990250] PlotlyKaleido v2.2.5 `~/.julia/dev/PlotlyKaleido`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants