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.
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.
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/. 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 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). I’m using matplotlib 3.1.1, the latest version of today; you can check the version you’re using as follows:
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.