문제

With gnuplot, I need to setup export GDFONTPATH=${HOME}/fonts for showing correct font. Or, I have this warning message "Could not find/open font when opening font "arial", using internal non-scalable font".

With Python, I try to automate invoking gnuplot with this code.

GNUPLOT=distutils.spawn.find_executable('gnuplot')        
my_env = os.environ
my_env["GDFONTPATH"] = '${HOME}/fonts'
p = Popen([GNUPLOT, config["file_path"]], shell=False, env=my_env)
p.communicate()

However, I have the warning message. What might be wrong? How to apply the environment variable in Python?

Could not find/open font when opening font "arial", using internal non-scalable font
도움이 되었습니까?

해결책

I have a feeling the issue that you're using '${HOME}' directly. Try this instead:

my_env['GDFONTPATH'] = os.path.join(my_env['HOME'], 'fonts')

다른 팁

Let me propose a somewhat different solution:

The pngcairo terminal, which by the way produces much better results than the png terminal, and the other cairo terminals (wxt and pdfcairo) use fontconfig.

With this, you must only create a file ~/.fonts.conf with the content:

<?xml version="1.0"?><!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
 <dir>~/fonts</dir>
</fontconfig>

and thats it. (Possibly you must check the available font names with e.g. fc-list | grep $HOME/fonts, but usually the font file names are self-explanatory). Then use e.g.

set terminal pngcairo font 'DroidSerif'

(Tested here with gnuplot 4.6.4)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top