PyGnuplot icon indicating copy to clipboard operation
PyGnuplot copied to clipboard

How to use PyGnuplot with Jupyter notebook!

Open benschneider opened this issue 2 years ago • 0 comments

The easiest way I found is the following:

from PyGnuplot import gp
from IPython.display import Image

def set_jpeg(g0, out_file):
    g0.default_term = 'jpeg'
    g0.file = out_file
    g0.c('set out "' + str(g0.file) + '"')
    g0.c('set term ' + g0.default_term)
    return g0.a()

g1 = gp()
set_jpeg(g1, 'g1.jpeg')

g1.a('plot sin(x)')  # gnuplot writes plot to 'g1.jpeg'
Image(g1.file)  # shows the plot for g1 (g1.jpeg)

benschneider avatar Jul 24 '23 22:07 benschneider