Frage

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
War es hilfreich?

Lösung

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')

Andere Tipps

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)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top