Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Plot Legend for Dyntools

tl;dr - How do I change the legend in dyntools plots?

At the moment, I am trying to compare two .out files which are both saved with the same file name in different folders. The .out files are of the same case with slight differences and therefore have the exact same channels which is the point of the code, to compare the channels with slight differences. My problem is that I cannot seem to find any option to change the legend of the plots. I can plot the files fine, its just that the legend has the same channel data with either an A or a B next to it. There is references at the top of the file as to which folder they came from, however I would like to make this a lot clearer and put it in the legend of the graph itself. I also find, that occasionally the plots are backward with the usual blue plot being printed in red and vice versa. Image of current plot cannot be uploaded due to low karma.

code for those interested (although probably unnecessary:

def plot_out_file(folder=[], outfile='', chans=None):
"""  Plot specific channels from the out file specified and save as subplots on one image.

:param folder: Folder location that the outfile can be found
:param outfile: The file name of the out file to be plotted
:param chans: The channels of the out file to be plotted
:return:
"""

# if there are no channels, assume all channels
if chans is None:
    chans = []
chnfobj, optnchn, optnppg, optnfmt = [], [], [], []
# Load the outfile and extract the data

outlist = []
if isinstance(folder, list):
    for fol in folder:
        outlist.append(os.path.join(fol, outfile))
    chnfobj = (dyntools.CHNF(outlist))

else:
    chnfobj = dyntools.CHNF(os.path.join(folder, outfile))

sh_ttl, ch_id, ch_data = chnfobj.get_data()

# Determine the structure of the subplots (rows and columns based on the number of channels)
count = len(chans)
if (count == 1):
    nRows = 1
    nCols = 1
elif (count == 2):
    nRows = 2
    nCols = 1
elif (count == 3):
    nRows = 3
    nCols = 1
elif (count == 4):
    nRows = 2
    nCols = 2
elif (count in [5, 6]):
    nRows = 4
    nCols = 2
elif (count in [7, 8, 9]):
    nRows = 4
    nCols = 2
elif (count in [10, 11, 12]):
    nRows = 4
    nCols = 3
else:
    nRows = 4
    nCols = 2

# Determine the options for the subplots
optnchn = dict()
optnppg = {'size': 'A3', 'orientation': 'Portrait'}  # 'Letter', 'Legal', 'A3', 'A4',     #'Portrait', 'Landscape'
optnfmt = {'rows': nRows, 'columns': nCols, 'dpi': 300, 'showttl': True}

plotID = 1
for i in range(0, len(chans)):
    ch = dict()
    for fol in folder:
        ch[os.path.join(fol, outfile)] = chans[i]

    if isinstance(chans[i], list):
        id = ch_id[chans[i][0]]
    else:
        id = ch_id[chans[i]]
    optnchn[plotID] = {'chns': ch,
                       'title': id,
                       'xscale': [0, 15]}
    plotID = plotID + 1
time = str(datetime.datetime.now().strftime("%Y%m%d%H%M"))
# print os.path.join(folder, outfile)
# Plot the out file and save with the same file name with a *.png attachment
file_str = os.path.join(folder[0], outfile).replace('.out', '.png')
file_str = file_str.split(".png", 1)
file_str = file_str[0] + "_" + str(datetime.datetime.now().strftime("%Y%m%d%H%M%S")) + ".png"
# file_str = file_str[0] + ".png"
figfiles = chnfobj.xyplots(optnchn, optnppg, optnfmt, file_str)
if figfiles:
    print 'Plot fils saved:'
    for f in figfiles:
        print '    ', f
chnfobj.plots_close()

Plot Legend for Dyntools

tl;dr - How do I change the legend in dyntools plots?

At the moment, I am trying to compare two .out files which are both saved with the same file name in different folders. The .out files are of the same case with slight differences and therefore have the exact same channels which is the point of the code, to compare the channels with slight differences. My problem is that I cannot seem to find any option to change the legend of the plots. I can plot the files fine, its just that the legend has the same channel data with either an A or a B next to it. There is references at the top of the file as to which folder they came from, however I would like to make this a lot clearer and put it in the legend of the graph itself. I also find, that occasionally the plots are backward with the usual blue plot being printed in red and vice versa. Image of current plot cannot be uploaded due to low karma.

code for those interested (although probably unnecessary:

def plot_out_file(folder=[], outfile='', chans=None):
"""  Plot specific channels from the out file specified and save as subplots on one image.

:param folder: Folder location that the outfile can be found
:param outfile: The file name of the out file to be plotted
:param chans: The channels of the out file to be plotted
:return:
"""

# if there are no channels, assume all channels
if chans is None:
    chans = []
chnfobj, optnchn, optnppg, optnfmt = [], [], [], []
# Load the outfile and extract the data

outlist = []
if isinstance(folder, list):
    for fol in folder:
        outlist.append(os.path.join(fol, outfile))
    chnfobj = (dyntools.CHNF(outlist))

else:
    chnfobj = dyntools.CHNF(os.path.join(folder, outfile))

sh_ttl, ch_id, ch_data = chnfobj.get_data()

# Determine the structure of the subplots (rows and columns based on the number of channels)
count = len(chans)
if (count == 1):
    nRows = 1
    nCols = 1
elif (count == 2):
    nRows = 2
    nCols = 1
elif (count == 3):
    nRows = 3
    nCols = 1
elif (count == 4):
    nRows = 2
    nCols = 2
elif (count in [5, 6]):
    nRows = 4
    nCols = 2
elif (count in [7, 8, 9]):
    nRows = 4
    nCols = 2
elif (count in [10, 11, 12]):
    nRows = 4
    nCols = 3
else:
    nRows = 4
    nCols = 2

# Determine the options for the subplots
optnchn = dict()
optnppg = {'size': 'A3', 'orientation': 'Portrait'}  # 'Letter', 'Legal', 'A3', 'A4',     #'Portrait', 'Landscape'
optnfmt = {'rows': nRows, 'columns': nCols, 'dpi': 300, 'showttl': True}

plotID = 1
for i in range(0, len(chans)):
    ch = dict()
    for fol in folder:
        ch[os.path.join(fol, outfile)] = chans[i]

    if isinstance(chans[i], list):
        id = ch_id[chans[i][0]]
    else:
        id = ch_id[chans[i]]
    optnchn[plotID] = {'chns': ch,
                       'title': id,
                       'xscale': [0, 15]}
    plotID = plotID + 1
time = str(datetime.datetime.now().strftime("%Y%m%d%H%M"))
# print os.path.join(folder, outfile)
# Plot the out file and save with the same file name with a *.png attachment
file_str = os.path.join(folder[0], outfile).replace('.out', '.png')
file_str = file_str.split(".png", 1)
file_str = file_str[0] + "_" + str(datetime.datetime.now().strftime("%Y%m%d%H%M%S")) + ".png"
# file_str = file_str[0] + ".png"
figfiles = chnfobj.xyplots(optnchn, optnppg, optnfmt, file_str)
if figfiles:
    print 'Plot fils saved:'
    for f in figfiles:
        print '    ', f
chnfobj.plots_close()

Plot Legend for Dyntools

tl;dr - How do I change the legend in dyntools plots?

At the moment, I am trying to compare two .out files which are both saved with the same file name in different folders. The .out files are of the same case with slight differences and therefore have the exact same channels which is the point of the code, to compare the channels with slight differences. My problem is that I cannot seem to find any option to change the legend of the plots. I can plot the files fine, its just that the legend has the same channel data with either an A or a B next to it. There is references at the top of the file as to which folder they came from, however I would like to make this a lot clearer and put it in the legend of the graph itself. I also find, that occasionally the plots are backward with the usual blue plot being printed in red and vice versa. Image of current plot cannot be uploaded due to low karma.

code for those interested (although probably unnecessary:

def plot_out_file(folder=[], outfile='', chans=None):
"""  Plot specific channels from the out file specified and save as subplots on one image.

:param folder: Folder location that the outfile can be found
:param outfile: The file name of the out file to be plotted
:param chans: The channels of the out file to be plotted
:return:
"""

# if there are no channels, assume all channels
if chans is None:
    chans = []
chnfobj, optnchn, optnppg, optnfmt = [], [], [], []
# Load the outfile and extract the data

outlist = []
if isinstance(folder, list):
    for fol in folder:
        outlist.append(os.path.join(fol, outfile))
    chnfobj = (dyntools.CHNF(outlist))

else:
    chnfobj = dyntools.CHNF(os.path.join(folder, outfile))

sh_ttl, ch_id, ch_data = chnfobj.get_data()

# Determine the structure of the subplots (rows and columns based on the number of channels)
count = len(chans)
if (count == 1):
    nRows = 1
    nCols = 1
elif (count == 2):
    nRows = 2
    nCols = 1
elif (count == 3):
    nRows = 3
    nCols = 1
elif (count == 4):
    nRows = 2
    nCols = 2
elif (count in [5, 6]):
    nRows = 4
    nCols = 2
elif (count in [7, 8, 9]):
    nRows = 4
    nCols = 2
elif (count in [10, 11, 12]):
    nRows = 4
    nCols = 3
else:
    nRows = 4
    nCols = 2

# Determine the options for the subplots
optnchn = dict()
optnppg = {'size': 'A3', 'orientation': 'Portrait'}  # 'Letter', 'Legal', 'A3', 'A4',     #'Portrait', 'Landscape'
optnfmt = {'rows': nRows, 'columns': nCols, 'dpi': 300, 'showttl': True}

plotID = 1
for i in range(0, len(chans)):
    ch = dict()
    for fol in folder:
        ch[os.path.join(fol, outfile)] = chans[i]

    if isinstance(chans[i], list):
        id = ch_id[chans[i][0]]
    else:
        id = ch_id[chans[i]]
    optnchn[plotID] = {'chns': ch,
                       'title': id,
                       'xscale': [0, 15]}
    plotID = plotID + 1
time = str(datetime.datetime.now().strftime("%Y%m%d%H%M"))
# print os.path.join(folder, outfile)
# Plot the out file and save with the same file name with a *.png attachment
file_str = os.path.join(folder[0], outfile).replace('.out', '.png')
file_str = file_str.split(".png", 1)
file_str = file_str[0] + "_" + str(datetime.datetime.now().strftime("%Y%m%d%H%M%S")) + ".png"
# file_str = file_str[0] + ".png"
figfiles = chnfobj.xyplots(optnchn, optnppg, optnfmt, file_str)
if figfiles:
    print 'Plot fils saved:'
    for f in figfiles:
        print '    ', f
chnfobj.plots_close()

Plot Legend for Dyntools

tl;dr - How do I change the legend in dyntools plots?

At the moment, I am trying to compare two .out files which are both saved with the same file name in different folders. The .out files are of the same case with slight differences and therefore have the exact same channels which is the point of the code, to compare the channels with slight differences. My problem is that I cannot seem to find any option to change the legend of the plots. I can plot the files fine, its just that the legend has the same channel data with either an A or a B next to it. There is references at the top of the file as to which folder they came from, however I would like to make this a lot clearer and put it in the legend of the graph itself. I also find, that occasionally the plots are backward with the usual blue plot being printed in red and vice versa. Image of current plot cannot be uploaded due to low karma.

code for those interested (although probably unnecessary:

def plot_out_file(folder=[], outfile='', chans=None):
"""  Plot specific channels from the out file specified and save as subplots on one image.

:param folder: Folder location that the outfile can be found
:param outfile: The file name of the out file to be plotted
:param chans: The channels of the out file to be plotted
:return:
"""

# if there are no channels, assume all channels
if chans is None:
    chans = []
chnfobj, optnchn, optnppg, optnfmt = [], [], [], []
# Load the outfile and extract the data

outlist = []
if isinstance(folder, list):
    for fol in folder:
        outlist.append(os.path.join(fol, outfile))
    chnfobj = (dyntools.CHNF(outlist))

else:
    chnfobj = dyntools.CHNF(os.path.join(folder, outfile))

sh_ttl, ch_id, ch_data = chnfobj.get_data()

# Determine the structure of the subplots (rows and columns based on the number of channels)
count = len(chans)
if (count == 1):
    nRows = 1
    nCols = 1
elif (count == 2):
    nRows = 2
    nCols = 1
elif (count == 3):
    nRows = 3
    nCols = 1
elif (count == 4):
    nRows = 2
    nCols = 2
elif (count in [5, 6]):
    nRows = 4
    nCols = 2
elif (count in [7, 8, 9]):
    nRows = 4
    nCols = 2
elif (count in [10, 11, 12]):
    nRows = 4
    nCols = 3
else:
    nRows = 4
    nCols = 2

# Determine the options for the subplots
optnchn = dict()
optnppg = {'size': 'A3', 'orientation': 'Portrait'}  # 'Letter', 'Legal', 'A3', 'A4',     #'Portrait', 'Landscape'
optnfmt = {'rows': nRows, 'columns': nCols, 'dpi': 300, 'showttl': True}

plotID = 1
for i in range(0, len(chans)):
    ch = dict()
    for fol in folder:
        ch[os.path.join(fol, outfile)] = chans[i]

    if isinstance(chans[i], list):
        id = ch_id[chans[i][0]]
    else:
        id = ch_id[chans[i]]
    optnchn[plotID] = {'chns': ch,
                       'title': id,
                       'xscale': [0, 15]}
    plotID = plotID + 1
time = str(datetime.datetime.now().strftime("%Y%m%d%H%M"))
# print os.path.join(folder, outfile)
# Plot the out file and save with the same file name with a *.png attachment
file_str = os.path.join(folder[0], outfile).replace('.out', '.png')
file_str = file_str.split(".png", 1)
file_str = file_str[0] + "_" + str(datetime.datetime.now().strftime("%Y%m%d%H%M%S")) + ".png"
# file_str = file_str[0] + ".png"
figfiles = chnfobj.xyplots(optnchn, optnppg, optnfmt, file_str)
if figfiles:
    print 'Plot fils saved:'
    for f in figfiles:
        print '    ', f
chnfobj.plots_close()