2016-12-01 66 views
1

我有一个包含文件的一些命令:不在gnuplot的相同的字体使用命令行或gnuplot的命令时

$ cat components.plg 
    set terminal png 
    set output output 
    set font "Helvetica,10" 
    unset xtics 
    unset ytics 
    unset border 
    plot "reportGraph_0" with lines title "Component 0", "reportGraph_1" with lines title "Component 1", "aoi.txt" with lines title "Area of interest" 
    $ 

我将不会显示的reportGraph_#这里的内容,但任何在他们2分已验证。

然后我用这个文件作为参数启动gnuplot,然后我得到一个关于Arial的警告(我不完全确定为什么)。

$ gnuplot -e "output='footprint.png' " components.plg 
    Could not find/open font when opening font "arial", using internal non-scalable font 
    $ 

但是,结果图像在非Helvetica中有其文本(但更多的是像无等宽字体sans)。

下面是两个图像(第一个是命令行的输出,第二个是在gnuplot外壳中启动的相同命令序列的输出,以及导出结果图像的输出)。有一个区别,我没有使用gnuplot中的前两个命令(set terminal pngset output output) - 我只是将映像“导出”为png。 image from shell command line image from gnuplot commands

问题是:为什么我在这两个图像中没有相同的字体? 我想要Helvetica(或Lucida Grande,但不是等宽字体)。

回答

1

Gnuplot有各种各样的终端。当你启动一个交互式gnuplot会话并且可能使用wxtqt终端。通过从图窗口中导出图像,您可以保存图像,这些图像是由这些终端创建的。

现在,使用set terminal png您可以使用一个不同的,相当老的终端,具有不同的功能,特别是在字体渲染方面。

如果要直接将图像保存为png,请使用pngcairo终端,该终端会生成更高质量的图像(结果应该等于从wxt导出的图像的结果)。

pngcairopdfcairo终端也应该正确处理您的字体。

+0

这可能是个窍门,但是这些终端对于我的机器来说是未知的:'第1行:未知或模棱两可的终端类型;为列表键入'set terminal' – fzd

1

png终端比pngcairo旧,但它仍然可以使用指定的字体。您只需指定一个.TTF路径或.pfa字体文件:

set terminal png font "/path/to/your/Helvetica.pfa"

或用逗号分隔的对字体文件的路径和点大小:

set terminal png font '/usr/share/fonts/liberation/LiberationSans-Regular.ttf,9'

的gnuplot使用libgd,因此如果将环境变量GDFONTPATH设置为包含.ttf或.pfa字体文件的目录,则可以只指定字体名称而不是完整路径:

set terminal png font 'LiberationSans-Regular'

用于设置不同终端字体的文档可在gnuplot中的help fonts gd,help fonts cairohelp fonts postscript下获得。