# How to using Japanese characteristic in plot

**URL:** <https://discourse.julialang.org/t/how-to-using-japanese-characteristic-in-plot/27613>\
**Category:** New to Julia\
**Tags:** plotting, juliabox\
**Created:** [August 16, 2019, 11:46am UTC](https://discourse.julialang.org/t/how-to-using-japanese-characteristic-in-plot/27613 "2019-08-16T11:46:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nguyen\_HongSon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nguyen_hongson/32/9803_2.png) [@Nguyen\_HongSon](https://discourse.julialang.org/u/Nguyen_HongSon)\
**Post date:** [August 16, 2019, 11:46am UTC](https://discourse.julialang.org/t/how-to-using-japanese-characteristic-in-plot/27613/1 "2019-08-16T11:46:13Z")

</div>

Hi every body,

I am very new about the Julia and Juliabox also.  
I am making a graphs using PyPlot on Juliabox.  
I want to set Legend and axes labels in Japanese.  
But it is not work at all, the Japanese park is shown as rectangular box.

Could any one help me to solve this problem?  
PS. I do not install any program in my computer. All I do that is in the Google Chrome .

Thank you very much.

 ![Julia%20Plot%20Japanese%20font](https://global.discourse-cdn.com/julialang/original/3X/2/e/2e94c6ba455b34abe94ae9fc07db15bb0abe1e12.png)

---

<div class="post-metadata">

**Author:** ![bicycle1885](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bicycle1885/32/107_2.png) [@bicycle1885](https://discourse.julialang.org/u/bicycle1885)\
**Post date:** [August 16, 2019, 8:51pm UTC](https://discourse.julialang.org/t/how-to-using-japanese-characteristic-in-plot/27613/2 "2019-08-16T20:51:16Z")

</div>

Hi,

I think this is one of the most difficult questions to solve remotely because many factors are involved in the problem. You can find numerous blog posts about it if you google it in Japanese. But I’d like to help you as much as I can.

First, let’s try the following script. The third line specifies the font family used in your plot.

```julia
using PyPlot

rc("font", family = "Noto Sans CJK JP") 
x = range(0, 2π, step = 0.2)
plot(x, sin.(x), label = "サイン波")
plot(x, cos.(x), label = "コサイン波")
legend()
title("日本語タイトル")
xlabel("x軸")
ylabel("y軸")
savefig("plot.png")

```

If you are lucky, you can see something like this.  
 ![plot](https://global.discourse-cdn.com/julialang/original/3X/8/2/82da77e9b75e77383a0f3862a8aee8fe5dff4c7c.png)

If you see some errors, you may not have the font used in the example above. The font name is “Noto Sans CJK JP”, which covers almost all Japanese characters. The font file can be downloaded from [https://www.google.com/get/noto/](https://www.google.com/get/noto/). Alternatively, you can specify your favorite font name instead of it. If you are using macOS or Windows, I believe several Japanese fonts are available out of box.

If it still doesn’t work, matplotlib may refer to a staled font file cache. This seems to happen when you install matplotlib before fonts. You can remove the cache file and try it again. On Linux, the cache file is located in `~/.cache/matplotlib/`. See [here](https://matplotlib.org/3.1.1/faq/troubleshooting_faq.html#matplotlib-configuration-and-cache-directory-locations) for more details about the cache file location.

If you are using some old matplotlib, several Japanese fonts may not be usable because the support of TrueType Collection or TTC, in which most Japanese fonts are encoded, was introduced recently ([Support (first font of) TTC files. by anntzer · Pull Request #9787 · matplotlib/matplotlib · GitHub](https://github.com/matplotlib/matplotlib/pull/9787)). I’m using matplotlib 3.1.1, the latest version of today; you can check the version you’re using as follows:

```julia
julia> using PyPlot

julia> matplotlib. __version__"3.1.1"

```

If you try all above and it still doesn’t work, I’m sorry I don’t know why. However, more information about your environment (specifically, operating system, python versions, available fonts, etc.) would be useful to help you.

---

<div class="post-metadata">

**Author:** ![bicycle1885](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bicycle1885/32/107_2.png) [@bicycle1885](https://discourse.julialang.org/u/bicycle1885)\
**Post date:** [August 16, 2019, 9:01pm UTC](https://discourse.julialang.org/t/how-to-using-japanese-characteristic-in-plot/27613/3 "2019-08-16T21:01:24Z")

</div>

Ah, I missed you wrote you used JuliaBox. In that case, installing new fonts may be difficult. You can list all available fonts as follows. If you can find a Japanese font there, you can use it instead of Noto Sans CJK JP.

```julia
julia> using PyPlot

julia> matplotlib.font_manager.fontManager.ttflist
440-element Array{PyCall.PyObject,1}:
 PyObject <Font 'STIXSizeTwoSym' (STIXSizTwoSymReg.ttf) normal normal regular normal>
 PyObject <Font 'STIXNonUnicode' (STIXNonUni.ttf) normal normal regular normal>
 PyObject <Font 'STIXGeneral' (STIXGeneralItalic.ttf) italic normal 400 normal>
 PyObject <Font 'STIXSizeFourSym' (STIXSizFourSymBol.ttf) normal normal bold normal>
 PyObject <Font 'DejaVu Sans' (DejaVuSans-Oblique.ttf) oblique normal 400 normal>
 PyObject <Font 'cmex10' (cmex10.ttf) normal normal 400 normal>
 PyObject <Font 'DejaVu Serif' (DejaVuSerif-BoldItalic.ttf) italic normal bold normal>
 PyObject <Font 'STIXSizeOneSym' (STIXSizOneSymBol.ttf) normal normal bold normal>
 PyObject <Font 'DejaVu Sans Mono' (DejaVuSansMono.ttf) normal normal 400 normal>
 PyObject <Font 'STIXSizeThreeSym' (STIXSizThreeSymBol.ttf) normal normal bold normal>
 PyObject <Font 'STIXGeneral' (STIXGeneralBolIta.ttf) italic normal bold normal>
 ⋮
 PyObject <Font 'Noto Serif Lao' (NotoSerifLao-Bold.ttf) normal normal bold normal>
 PyObject <Font 'Noto Sans Ol Chiki' (NotoSansOlChiki-Regular.ttf) normal normal regular normal>
 PyObject <Font 'Noto Sans Thai' (NotoSansThai-Regular.ttf) normal normal regular normal>
 PyObject <Font 'Noto Sans Linear B' (NotoSansLinearB-Regular.ttf) normal normal regular normal>
 PyObject <Font 'Lohit Telugu' (Lohit-Telugu.ttf) normal normal 400 normal>
 PyObject <Font 'Noto Sans Adlam Unjoined' (NotoSansAdlamUnjoined-Regular.ttf) normal normal regular normal>
 PyObject <Font 'Noto Sans Meetei Mayek' (NotoSansMeeteiMayek-Regular.ttf) normal normal 400 normal>
 PyObject <Font 'Tlwg Typewriter' (TlwgTypewriter-BoldOblique.ttf) oblique normal bold normal>
 PyObject <Font 'Noto Sans Mono' (NotoSansMono-Regular.ttf) normal normal regular normal>
 PyObject <Font 'Purisa' (Purisa-Oblique.ttf) oblique normal 400 normal>

```

---

<div class="post-metadata">

**Author:** ![Nguyen\_HongSon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nguyen_hongson/32/9803_2.png) [@Nguyen\_HongSon](https://discourse.julialang.org/u/Nguyen_HongSon)\
**Post date:** [August 17, 2019, 2:57am UTC](https://discourse.julialang.org/t/how-to-using-japanese-characteristic-in-plot/27613/4 "2019-08-17T02:57:59Z")

</div>

Hi Bicycle 1885 (Kenta Sato san)

Thank you very much for your reply.  
I have searched about this problem by Japanese, however, most of the suggestions are install the font or edit matplotlibrc file.  
But is you mentioned, it is not possible when I am using Juliabox without install anything.  
I would like to try ti find the Japanese font in the JuliaBox, but it is huge data coming.  
Could you please teach me how to filter only Japanese fonts?

Thank and Best regards,

---

<div class="post-metadata">

**Author:** ![bicycle1885](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bicycle1885/32/107_2.png) [@bicycle1885](https://discourse.julialang.org/u/bicycle1885)\
**Post date:** [August 17, 2019, 7:50am UTC](https://discourse.julialang.org/t/how-to-using-japanese-characteristic-in-plot/27613/5 "2019-08-17T07:50:08Z")

</div>

I looked over the font list but unfortunately I couldn’t find any promising font. However, I found a workaround. You can specify `FontProperties` like below:

```julia
# Download a Japanese font.
download("https://noto-website-2.storage.googleapis.com/pkgs/NotoSansCJKjp-hinted.zip", "NotoSansCJKjp-hinted.zip")
run(`unzip NotoSansCJKjp-hinted.zip NotoSansCJKjp-Regular.otf`)

# Initialize FontProperties.
fontprops = matplotlib[:font_manager][:FontProperties](fname = "NotoSansCJKjp-Regular.otf")

# Pass the FontProperty object to title, xlabel, ylabel etc.
x = range(0, 2π, step = 0.1)
plot(x, sin.(x))
title("日本語タイトル", fontproperties = fontprops)
xlabel("x軸", fontproperties = fontprops)
ylabel("y軸", fontproperties = fontprops);

```

I know this is hacky and this may be an unrecommended way. But it works.

---

<div class="post-metadata">

**Author:** ![Nguyen\_HongSon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nguyen_hongson/32/9803_2.png) [@Nguyen\_HongSon](https://discourse.julialang.org/u/Nguyen_HongSon)\
**Post date:** [August 18, 2019, 8:33am UTC](https://discourse.julialang.org/t/how-to-using-japanese-characteristic-in-plot/27613/6 "2019-08-18T08:33:44Z")

</div>

Hi bicycle 1885

With your help, I can make my graphs with the legend in Japanese perfectly.  
Thank you very much.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 18, 2019, 9:12am UTC](https://discourse.julialang.org/t/how-to-using-japanese-characteristic-in-plot/27613/7 "2019-08-18T09:12:30Z")

</div>

I had an example here for PGFPlotsX which could be modified:

> [@Why in plots，plot can't correctly display chinese](https://discourse.julialang.org/t/why-in-plots-plot-cant-correctly-display-chinese/19511/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)

Incidentally, if someone happens to be using pgfplots with CJK characters, contributing an example at

> **[GitHub - KristofferC/PGFPlotsX.jl: Plots in Julia using the PGFPlots LaTeX...](https://github.com/KristofferC/PGFPlotsX.jl)**
>
> Plots in Julia using the PGFPlots LaTeX package. Contribute to KristofferC/PGFPlotsX.jl development by creating an account on GitHub.

would be appreciated.
