Why in plots,plot can't correctly display chinese

using Plots

How is this question different from your last posted topic?


Please provide a full example with the output that you get. I suspect that you’re having issues not because of the Chinese text but because you’re using Unicode double quotes instead of ".

Edit: no, it looks like that’s an artifact of the code not being quoted. If it’s quoted it looks like this:

using Plots

see: https://github.com/JuliaPlots/Plots.jl/issues/791

You don’t say what the error is? Also you should specify what backend you are using — what is Plots.backend()?

If you are using the Matplotlib backend, note that you often have to change the font settings with Matplotlib to ensure that Unicode characters render correctly, as the default font does not have good Unicode coverage.

1 Like

Someone who knows more about CJK in LaTeX may be able to simplify this:

using PGFPlotsX

# run this just once, to setup PGFPlotsX
push!(PGFPlotsX.CUSTOM_PREAMBLE, raw"\usepackage{CJKutf8}",

# the actual plot
p = @pgf Axis({title = raw"\zh{图形}" }, Plot(Coordinates(enumerate(rand(10)))))

# we also save it
pgfsave("/tmp/test.pdf", p)


gr as backend,I will try https://github.com/JuliaPlots/Plots.jl/issues/791

result like this,the gr backend can’t display CJK correctly

using PlotlyJS can display chinese correctly
using Plots;plotlyjs()

Try the PlotlyJS backend – that seems to work.
(You’ll need to update your packages to get the latest update to Plots to be able to use that backend.)

1 Like