From 18b4566ab4a9e67947b80be07598e09bd2532546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=2E=20Brandenburg?= Date: Sun, 23 May 2010 18:00:16 -0400 Subject: support writing files for plot3d --- util.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'util.py') diff --git a/util.py b/util.py index 480ae5f..7d81d4f 100644 --- a/util.py +++ b/util.py @@ -8,7 +8,8 @@ def load_csv_file(fname, *args, **kargs): f.close() # don't leak file handles return data -def write_csv_file(fname, rows, header=None, width=None): +def write_csv_file(fname, rows, header=None, width=None, + break_col=None): if fname is None: f = Tmp() else: @@ -22,10 +23,17 @@ def write_csv_file(fname, rows, header=None, width=None): f.write('#') f.write(", ".join([fmt % str(x) for x in header])) f.write('\n') + last_row = None for row in rows: + # Insert extra line breaks for Gnuplot plot3d plotting whenever + # the value of break_col changes. + if not last_row is None and not break_col is None: + if last_row[break_col] != row[break_col]: + f.write('\n') f.write(' ') f.write(", ".join([fmt % str(x) for x in row])) f.write('\n') + last_row = row if fname is None: # keep it open f.flush() -- cgit v1.2.2