TuringLang / MCMCChains.jl

Types and utility functions for summarizing Markov chain Monte Carlo simulations
https://turinglang.org/MCMCChains.jl/
Other
266 stars 29 forks source link

Unicode or LaTeX labels in plots #111

Open BenjaminBorn opened 5 years ago

BenjaminBorn commented 5 years ago

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?

cpfiffer commented 5 years ago

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