# Why in plots，plot can't correctly display chinese

#1

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

#2

How is this question different from your last posted topic?

#3

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="图形")


#4

#5

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.

#6

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)


#7

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

#8

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

#9

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

#10

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