Commit fffbd554 authored by Luke Campagnola's avatar Luke Campagnola
Browse files

Added CSV exporter (only for PlotItem)

parent 6aef8533
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui, QtCore
from Exporter import Exporter
from pyqtgraph.parametertree import Parameter
__all__ = ['CSVExporter']
class CSVExporter(Exporter):
Name = "CSV from plot data"
windows = []
def __init__(self, item):
Exporter.__init__(self, item)
self.params = Parameter(name='params', type='group', children=[
{'name': 'separator', 'type': 'list', 'value': 'comma', 'values': ['comma', 'tab']},
def parameters(self):
return self.params
def export(self, fileName=None):
if not isinstance(self.item, pg.PlotItem):
raise Exception("Matplotlib export currently only works with plot items")
if fileName is None:
self.fileSaveDialog(filter=["*.csv", "*.tsv"])
fd = open(fileName, 'w')
data = []
header = []
for c in self.item.curves:
header.extend(['x', 'y'])
if self.params['separator'] == 'comma':
sep = ','
sep = '\t'
fd.write(sep.join(header) + '\n')
i = 0
while True:
done = True
for d in data:
if i < len(d[0]):
fd.write('%g%s%g%s'%(d[0][i], sep, d[1][i], sep))
done = False
fd.write(' %s %s' % (sep, sep))
if done:
i += 1
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment