In plot.py/plotmpl.py, allowed escaped commas in certain comma-separated fields

This commit is contained in:
Christopher Haster
2023-01-20 02:45:47 -06:00
parent 9a8e1d93c6
commit 0eccd6515f
2 changed files with 30 additions and 19 deletions

View File

@@ -1410,6 +1410,7 @@ def main(csv_paths, *,
if __name__ == "__main__": if __name__ == "__main__":
import sys import sys
import argparse import argparse
import re
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="Plot CSV files in terminal.", description="Plot CSV files in terminal.",
allow_abbrev=False) allow_abbrev=False)
@@ -1476,8 +1477,10 @@ if __name__ == "__main__":
help="Characters to use for lines.") help="Characters to use for lines.")
parser.add_argument( parser.add_argument(
'--labels', '--labels',
type=lambda x: [x.strip() for x in x.split(',')], type=lambda x: [x.strip().replace('\,',',')
help="Comma-separated legend labels.") for x in re.split(r'(?<!\\),', x)],
help="Comma-separated legend labels. Allows '\,' as an "
"alternative for a literal ','.")
parser.add_argument( parser.add_argument(
'-W', '--width', '-W', '--width',
nargs='?', nargs='?',
@@ -1533,16 +1536,18 @@ if __name__ == "__main__":
help="Add a label to the y-axis.") help="Add a label to the y-axis.")
parser.add_argument( parser.add_argument(
'--xticklabels', '--xticklabels',
type=lambda x: type=lambda x: [x.strip().replace('\,',',')
[x.strip() for x in x.split(',')] for x in re.split(r'(?<!\\),', x)]
if x.strip() else [], if x.strip() else [],
help="Comma separated xticklabels.") help="Comma separated xticklabels. Allows '\,' as an "
"alternative for a literal ','.")
parser.add_argument( parser.add_argument(
'--yticklabels', '--yticklabels',
type=lambda x: type=lambda x: [x.strip().replace('\,',',')
[x.strip() for x in x.split(',')] for x in re.split(r'(?<!\\),', x)]
if x.strip() else [], if x.strip() else [],
help="Comma separated yticklabels.") help="Comma separated yticklabels. Allows '\,' as an "
"alternative for a literal ','.")
parser.add_argument( parser.add_argument(
'-t', '--title', '-t', '--title',
help="Add a title.") help="Add a title.")

View File

@@ -1071,6 +1071,7 @@ def main(csv_paths, output, *,
if __name__ == "__main__": if __name__ == "__main__":
import sys import sys
import argparse import argparse
import re
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="Plot CSV files with matplotlib.", description="Plot CSV files with matplotlib.",
allow_abbrev=False) allow_abbrev=False)
@@ -1137,13 +1138,16 @@ if __name__ == "__main__":
help="Comma-separated hex colors to use.") help="Comma-separated hex colors to use.")
parser.add_argument( parser.add_argument(
'--formats', '--formats',
type=lambda x: [x.strip().replace('0',',') for x in x.split(',')], type=lambda x: [x.strip().replace('\,',',')
help="Comma-separated matplotlib formats to use. Allows '0' as an " for x in re.split(r'(?<!\\),', x)],
"alternative for ','.") help="Comma-separated matplotlib formats to use. Allows '\,' as an "
"alternative for a literal ','.")
parser.add_argument( parser.add_argument(
'--labels', '--labels',
type=lambda x: [x.strip() for x in x.split(',')], type=lambda x: [x.strip().replace('\,',',')
help="Comma-separated legend labels.") for x in re.split(r'(?<!\\),', x)],
help="Comma-separated legend labels. Allows '\,' as an "
"alternative for a literal ','.")
parser.add_argument( parser.add_argument(
'-W', '--width', '-W', '--width',
type=lambda x: int(x, 0), type=lambda x: int(x, 0),
@@ -1206,16 +1210,18 @@ if __name__ == "__main__":
help="Add a label to the y-axis.") help="Add a label to the y-axis.")
parser.add_argument( parser.add_argument(
'--xticklabels', '--xticklabels',
type=lambda x: type=lambda x: [x.strip().replace('\,',',')
[x.strip() for x in x.split(',')] for x in re.split(r'(?<!\\),', x)]
if x.strip() else [], if x.strip() else [],
help="Comma separated xticklabels.") help="Comma separated xticklabels. Allows '\,' as an "
"alternative for a literal ','.")
parser.add_argument( parser.add_argument(
'--yticklabels', '--yticklabels',
type=lambda x: type=lambda x: [x.strip().replace('\,',',')
[x.strip() for x in x.split(',')] for x in re.split(r'(?<!\\),', x)]
if x.strip() else [], if x.strip() else [],
help="Comma separated yticklabels.") help="Comma separated yticklabels. Allows '\,' as an "
"alternative for a literal ','.")
parser.add_argument( parser.add_argument(
'-t', '--title', '-t', '--title',
help="Add a title.") help="Add a title.")