MCMCChains.jl icon indicating copy to clipboard operation
MCMCChains.jl copied to clipboard

Unicode or LaTeX labels in plots

Open BenjaminBorn opened this issue 5 years ago • 1 comments

Sorry for yet another question. My parameter names contain Greek letters, e.g. or . In standard Julia plots, I can pass a LaTeXString for labelling. Is this also possible here or would I have to write my own plotting code for the chains? Or do you recommend a different approach?

BenjaminBorn avatar May 28 '19 16:05 BenjaminBorn

From what I remember, this is a problem upstream with the GR backend for plots. Check out this issue: https://github.com/jheinen/GR.jl/issues/143.

It's a bit hacky, but there is a fix outside of rolling your own plots. You can try setting ENV["GKS_ENCODING"]="utf-8" before you load StatsPlots:

ENV["GKS_ENCODING"]="utf-8"
using Turing, StatsPlots

@model gdemo(x1, x2) = begin
    σ² ~ InverseGamma(2,3)
    μ ~ Normal(0, sqrt(σ²))
    x1 ~ Normal(μ, sqrt(σ²))
    x2 ~ Normal(μ, sqrt(σ²))
end

model = gdemo(2.3, 1.5)
c = sample(model, HMC(500, 0.01, 5))
plot(c)

This gives me

example

For whatever reason it won't print the sigma character.

If you'd like to do your own plotting, I'd recommend extracting the parameters with chain.value to get an AxisArray, or calling DataFrame(chain, append_chains=false) to get an array of data frames (one per chain).

cpfiffer avatar May 28 '19 17:05 cpfiffer