PyGnuplot icon indicating copy to clipboard operation
PyGnuplot copied to clipboard

Error saving a pdf (on MacOS) using pdfcario

Open Nebuchadrezzar opened this issue 6 years ago • 3 comments

>>> import PyGnuplot as gp
>>> gp.c('plot sin(x)')
>>> gp.pdf('graph.pdf')
>>>

gnuplot> set term pdf enhanced size 14cm, 9cm color solid fsize 12 fname 'Helvetica';
                                                          ^
         line 0: unrecognized terminal option

Note: I have x11, aqua, and pdfcario terminals but not plain pdf. It looks as though pdfcario can't handle the "fsize and fname" arguments. It does accept: "font 'Helvetica,12"

Not working:

gnuplot> set term pdf enhanced size 14cm, 9cm color solid fsize 12 fname 'Helvetica'
Terminal type is now 'pdfcairo'
                                                          ^
         unrecognized terminal option

gnuplot> set term pdf enhanced size 14cm, 9cm color solid fname 'Helvetica'
Terminal type is now 'pdfcairo'
                                                          ^
         unrecognized terminal option

gnuplot> set term pdf enhanced size 14cm, 9cm color solid
Terminal type is now 'pdfcairo'
Options are ' transparent enhanced fontscale 0.5 size 14.00cm, 9.00cm '

This works:

gnuplot> set term pdf enhanced size 14cm, 9cm color solid font 'Helvetica,12'

Terminal type is now 'pdfcairo'
Options are ' transparent enhanced font "Helvetica,12" fontscale 0.5 size 14.00cm, 9.00cm '

Nebuchadrezzar avatar Aug 19 '18 18:08 Nebuchadrezzar

Perhaps a new function:

def pdfcario(filename='tmp.pdf', width=14, height=9, fontsize=12, term=default_term):
# Script to make gnuplot print into a pdf file using pdfcario term
    c('set term pdf enhanced size ' + str(width) + 'cm, ' + str(height) + 'cm  color solid font ' + ' "Helvetica,' + str(fontsize) + "' ;")
    c('set out "' + filename + '";')
    c('replot;')
    c('set term ' + str(term) + '; replot')

Nebuchadrezzar avatar Aug 19 '18 21:08 Nebuchadrezzar

Ahh yes, ideally would be a function which autodetects the best available terminal and method. I don't know yet how to read out gnuplot defaults on all platforms equally. Searching for it.

benschneider avatar Aug 20 '18 01:08 benschneider

What about a cruder approach of just detecting to OS system with something like:

import platform platform.platform()

Then selecting an appropriate terminal given the feedback from platform()? For Mac and Windows, using pdfcario instead of pdf seems to make more sense.

Nebuchadrezzar avatar Aug 20 '18 02:08 Nebuchadrezzar