0

I am trying to run my gnuplot commands from a Python script. I came across a suggestion that I can save all the gnuplot commands in a file (with format codes for the variables I need to drop in) and then just read that file in with Python and format it. However, I couldn't find any examples to understand how it's done. Can somebody help me out?

PS: I am using gnuplot version 4.2 and I have already tried using -e pipe but for some reason it doesn't work. PPS: I would prefer not to use Gnuplot-py package

3
  • possible duplicate of stackoverflow.com/questions/13204764/… Commented Feb 5, 2016 at 5:11
  • I used this package. It's old but it worked fine. Commented Feb 5, 2016 at 5:14
  • I would prefer not to use the Gnuplot-py package. Is there any alternate way? Commented Feb 5, 2016 at 5:18

1 Answer 1

1

A simple example: Start with a text file with formatting codes,

The {adjective1} {adjective2} {mammal1} has escaped!

Then in Python you can substitute values like so:

# load the template
with open("template.txt") as inf:
    template = inf.read()

# substitute values
result = template.format(
    adjective1 = "lazy",
    adjective2 = "brown",
    mammal1    = "bear"
)

# save the result
with open("plot.dem", "w") as outf:
    outf.write(result)

The plot.dem file now contains

The lazy brown bear has escaped!
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.