JuliaPlots / Plots.jl

Powerful convenience for Julia visualizations and data analysis
https://docs.juliaplots.org
Other
1.84k stars 355 forks source link

[BUG] GR backend does not support emoji in legend #4843

Open nathanrboyer opened 12 months ago

nathanrboyer commented 12 months ago

Related to #791, but that was supposedly fixed two years ago.

Details

The first SciML tutorial has you model 🐰 and 🐺 populations and use those emoji as variable names. However, this breaks the plot legend unless you switch the fontfamily or backend. The default font should work with Unicode without these workarounds for beginners.

Predator-Prey Dynamics

using ModelingToolkit, DifferentialEquations, Plots

# Define our state variables: state(t) = initial condition
@variables t 🐰(t)=1 🐺(t)=1 total(t)=2

# Define our parameters
@parameters α=1.5 β=1.0 γ=3.0 δ=1.0

# Define our differential: takes the derivative with respect to `t`
D = Differential(t)

# Define the differential equations
eqs = [
    D(🐰) ~ α * 🐰 - β * 🐰 * 🐺
    D(🐺) ~ -γ * 🐺 + δ * 🐰 * 🐺
    total ~ 🐰 + 🐺
]

# Bring these pieces together into an ODESystem with independent variable t
@named sys = ODESystem(eqs, t)

# Symbolically Simplify the System
simpsys = structural_simplify(sys)

# Convert from a symbolic to a numerical problem to simulate
tspan = (0.0, 10.0)
prob = ODEProblem(simpsys, [], tspan)

# Solve the ODE
sol = solve(prob)

# Plot the solution
# gr(fontfamily="Courier")   # this somewhat fixes the Julia render, but the png output is still broken.
p1 = plot(sol, title = "Rabbits vs Wolves")
p2 = plot(sol, idxs = total, title = "Total Animals")

p3 = plot(p1, p2, layout = (2, 1))
savefig(p3, "Predator-Prey Dynamics.png")
display(p3)

Predator-Prey Dynamics

image

Backends

This bug occurs on ( insert x below )

Backend yes no untested
gr (default) x
pythonplot x
plotlyjs x
pgfplotsx x
unicodeplots x
inspectdr x
gaston x

Versions

Plots.jl version: v1.39.0 Backend version (]st -m <backend(s)>): GR v0.72.10 Output of versioninfo():

Julia Version 1.10.0-rc1
Commit 5aaa948543 (2023-11-03 07:44 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 8 × Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, skylake)
  Threads: 1 on 8 virtual cores
Environment:
  JULIA_EDITOR = code.cmd
  JULIA_NUM_THREADS =
ujimushi commented 8 months ago

Since the GR backend can only select one ttf font file, it is not possible to display emojis in combination with Sagoe UI Emoji or Noto Color Emoji.

One possible solution is to use the Symbola font, which contains emojis in a single font file.

Please install Symbola_hint.ttf on your OS, then change the source list as follows and try it out.

p1 = plot(sol, title = "Rabbits vs Wolves", legendfontfamily="Symbola_hint")