Why in plots,plot can't correctly display chinese

using Plots
plot(rand(10),title=“图形”)

How is this question different from your last posted topic?

3 Likes

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
plot(rand(10),title="图形")

see: Error with unicode labels in GR backend · Issue #791 · JuliaPlots/Plots.jl · GitHub

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
PGFPlotsX.latexengine!(PGFPlotsX.PDFLATEX)
push!(PGFPlotsX.CUSTOM_PREAMBLE, raw"\usepackage{CJKutf8}",
      raw"\newcommand{\zh}[1]{\begin{CJK}{UTF8}{gbsn}#1\end{CJK}}")

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

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

4 Likes

gr as backend,I will try Error with unicode labels in GR backend · Issue #791 · JuliaPlots/Plots.jl · GitHub

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

using PlotlyJS can display chinese correctly
using Plots;plotlyjs()
plot(rand(10),title=“图形”)newplot

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