0
votes

I have python script which has an input arguments of min and max of y range and I want to plot the graph accordingly

test.py -m miny -i maxy

inside the python script gnuplotcmds.append('set yrange [miny:maxy]')

my question is , how can i use variable limits in the gnuplot command as when running this line it always read miny and maxy as strings not variables ?

2

2 Answers

2
votes

If miny and maxy are python variables, you must use something like

gnuplotcmds.append('set yrange[{0}:{1}]'.format(miny, maxy)

If you want to have a tight yrange, you could also use

gnuplotcmds.append('set autoscale yfix')
0
votes

First, you have to parse the values from the commandline within python:

import sys

miny=0.0
maxy=0.0
for i in len(sys.argv)-1:
    if(sys.argv[i] == "-m"):
        miny=float(sys.argv[i+1])
    if(sys.argv[i] == "-i"):
        maxy=float(sys.argv[i+1]

This is a very simple way to do that, but it does not check your parameters. For example, if there is no number after a -i in your command line, you run into trouble. There are more sophisticated methods like the getopts module, but for now, this code does the job.

As in Christhoph's answer, you can now use

gnuplotcmds.append('set yrange[{0}:{1}]'.format(miny, maxy)