Repository: pyqtgraph/pyqtgraph

Issue:
CSV export broken
### Short description
Export CSV failed when the plot name has decode error characters.

### Code to reproduce
```python
from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg

#QtGui.QApplication.setGraphicsSystem('raster')
app = QtGui.QApplication([])
win = pg.GraphicsLayoutWidget(show=True, title="Basic plotting examples")
win.resize(1000,600)
win.setWindowTitle('pyqtgraph example: Plotting')


pg.setConfigOptions(antialias=True)

pw = win.addPlot(title="Scatter plot, axis labels, log scale")
pw.addLegend()
pw .plot(np.random.normal(size=100), pen=(255,0,0), name="\u00A0下加热体")

QtGui.QApplication.instance().exec_()
```

### Expected behavior
Export CSV Success

### Real behavior
Export CSV Failed

```
---------------------------------------------------------------------------
UnicodeEncodeError                        Traceback (most recent call last)
c:\program files\python37\lib\site-packages\pyqtgraph\exporters\Exporter.py in fileSaveFinished(self, fileName)
     75                 fileName = fileName + '.' + selectedExt.lstrip('.')
     76
---> 77         self.export(fileName=fileName, **self.fileDialog.opts)
     78
     79     def getScene(self):

c:\program files\python37\lib\site-packages\pyqtgraph\exporters\CSVExporter.py in export(self, fileName)
     58
     59         with open(fileName, 'w') as fd:
---> 60             fd.write(sep.join(header) + '\n')
     61             i = 0
     62             numFormat = '%%0.%dg' % self.params['precision']

UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position 1: illegal multibyte sequence
```

### Tested environment(s)

 * PyQtGraph version: 0.11.0.dev0+g2203933
 * Qt Python binding: PyQt5 5.13.2 Qt 5.13.2
 * Python version: Python 3.7.5 
 * NumPy version: 1.17.4
 * Operating system: Windows 7 X64
 * Installation method: pip  git+

### Additional context
I use "\u00A0" because i want to add some space before label name in the legend.
Could i use the csv export by "utf-8" but not "gbk" ?



Discussion:
_Disclaimer: I'm not a developer of pyqtgraph, these are just my thoughts_

I suppose your system has the gbk encoding as its default which probably doesn't support Unicode's non-breaking-space (`\u00A0`)

The relevant lines of code are in pyqtgraph/CSVExporter.py lines 59/60:

```py
 with open(fileName, 'w') as fd:
            fd.write(sep.join(header) + '\n')
```

That `open` call doesn't have an explicit encoding parameter, so Python falls back to the system default: gbk. Then it tries to write a string containing your `\u00A0` using the gbk encoding - which fails.

It might be worthwhile to add an optional encoding parameter to the csv exporter so that users can explicitly set the encoding in cases where their system encoding doesn't match their strings.
unfortunately python2 does not support the `encoding` parameter, so not quite as easy as putting that there....that said PR #126 may actually fix the issue.

Resolving patch:
diff --git a/pyqtgraph/exporters/CSVExporter.py b/pyqtgraph/exporters/CSVExporter.py
--- a/pyqtgraph/exporters/CSVExporter.py
+++ b/pyqtgraph/exporters/CSVExporter.py
@@ -3,6 +3,7 @@
 from .Exporter import Exporter
 from ..parametertree import Parameter
 from .. import PlotItem
+from ..python2_3 import asUnicode
 
 __all__ = ['CSVExporter']
     
@@ -57,7 +58,7 @@ def export(self, fileName=None):
             sep = '\t'
 
         with open(fileName, 'w') as fd:
-            fd.write(sep.join(header) + '\n')
+            fd.write(sep.join(map(asUnicode, header)) + '\n')
             i = 0
             numFormat = '%%0.%dg' % self.params['precision']
             numRows = max([len(d[0]) for d in data])


Test patch: