Saturday, December 3, 2011

Multi-language support of gnuplot --- Using latex

For some non-English speakers, inserting some their own characters into the graph is usual. And for some fresh, this some times becomes a challenging task. This posts will talk about how to solve this problem using latex.

We know that some packages used latex can deal with multi-language typesetting. And we also know that gnuplot have terminals like latex, epslatex. So we can first plot a English graph with these terminals, then modify the output tex files, and at last get a multi-language supported graph. Take Chinese support for example.

We first plot a graph using the following script.

set term epslatex color standalone
set output "voltage.tex"
set xlabel "my xlabel"
set ylabel "my ylabel"
unset key
plot sin(x)+0.1*(2*rand(0)-1.) w l lw 2
set output

Compile the output tex file using latex we get a graph like the following one.
Gnuplot plotted graph without Chinese support
And we want to label the x-axes with "时间(秒)"(means time) and y-axes with "电压(伏)"(means voltage). To realize this effect, we open the tex file with any text editor and find lines

\put(4039,154){\makebox(0,0){\strut{}my xlabel}}%


\put(308,2739){\rotatebox{-270}{\makebox(0,0){\strut{}my ylabel}}}

Then we repalce "my xlabel" with "时间(秒)", "my ylabel" with "电压(伏)". And add the following codes into the header part of the file to get the chinese support of latex.

This time compile the tex file uising latex again. And a chinese supported graph is gotten.
Gnuplot plotted graph with Chinese support
The modified and pre-modified tex files can be downloaded here.
voltage.tex  voltage_chinese.tex


  1. How to use latex in gnuplot while I set output filetype to png?

  2. milk:
    You know that latex only deal with pictures with format ps and eps. For other formats you should do the conversion first.

  3. Your blog is great! Keep up the good work :)

  4. This is so fun! What a great idea. Also I love how authentic you seem to be. Your style and passion for blogging is contagious. Thank you for sharing your life!


Creative Commons License
Except as otherwise noted, the content of this page is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.