Repository: pyqtgraph/pyqtgraph

Issue:
Plot Options -> Average invokes thick pen plotting slow path
<!-- In the following, please describe your issue in detail! -->
<!-- If some of the sections do not apply, just remove them. -->

### Short description
<!-- This should summarize the issue. -->
Since #2011, thick pen plotting has become more usable. Plot Options -> Average uses a pen that is not supported by #2011, resulting in a very slow plot.

### Code to reproduce
<!-- Please provide a minimal working example that reproduces the issue in the code block below.
     Ideally, this should be a full example someone else could run without additional setup. -->
Run ```examples/crosshair.py```.
On the upper plot, right-click -> context menu -> ```Plot Options``` -> ```Average``` -> check ```average```

### Expected behavior
<!-- What should happen? -->

No slow-down

### Real behavior
<!-- What happens? -->

Panning (amongst other operations) will become very slow, to the extent of being unusable.


### Tested environment(s)

 * PyQtGraph version: <!-- output of pyqtgraph.__version__ --> git ef458d3bbae513f6e58604332acf3c901f304e9e
 * Qt Python binding: <!-- output of pyqtgraph.Qt.VERSION_INFO --> PyQt6 6.2.0
 * Python version: 3.10.0
 * NumPy version: <!-- output of numpy.__version__ --> 1.21.3
 * Operating system: Windows 10
 * Installation method: <!-- e.g. pip, conda, system packages, ... --> pip install -e .

### Additional context
In ```pyqtgraph/graphicsItems/PlotItem/PlotItem.py```, a shadow pen of color (0, 0, 0, 100), width=3 is created. Non-opaque pens are not supported by #2011, hence the slow-down.

Not sure what visual effect a non-opaque black pen is supposed to achieve.


Discussion:
Here is the relevant function that's called: 

https://github.com/pyqtgraph/pyqtgraph/blob/master/pyqtgraph/graphicsItems/PlotItem/PlotItem.py#L443-L495

> Not sure what visual effect a non-opaque black pen is supposed to achieve.

Given this code was created 10 years ago, and give it isn't really function in it's current form, I think it's completely legitimate to change this up to make it us the "fast" method.  
A non-opaque black shadow is a convenient way to make sure the line has at least limited contrast from the background.
The shadow-outline will be invisible when it is not needed on the default black background, but it will apply a (limited) darkening when drawing over a light color.

But usability should trump minor styling choices here, so I would also suggest to just change this to a pure black shadow pen. Ideally we would provide a way for the user to set pen / shadow_pen for the "average" function, then it can be styled as desired - including possible transparency when the performance hit is not a problem.

A good starting point might be defining them as properties of `PlotItem`:
``` python
self.avgPen = fn.mkPen([0, 200, 0]
self.avgShadowPen = fn.mkPen([0, 0, 0, 0], width=3)
```
That would make them at least somewhat accessible without defining a proper API right now.
There are enough other examples in the library where interaction requires directly accessing internal data structures.

Resolving patch:
diff --git a/pyqtgraph/examples/crosshair.py b/pyqtgraph/examples/crosshair.py
--- a/pyqtgraph/examples/crosshair.py
+++ b/pyqtgraph/examples/crosshair.py
@@ -16,6 +16,10 @@
 label = pg.LabelItem(justify='right')
 win.addItem(label)
 p1 = win.addPlot(row=1, col=0)
+# customize the averaged curve that can be activated from the context menu:
+p1.avgPen = pg.mkPen('#FFFFFF')
+p1.avgShadowPen = pg.mkPen('#8080DD', width=10)
+
 p2 = win.addPlot(row=2, col=0)
 
 region = pg.LinearRegionItem()
diff --git a/pyqtgraph/graphicsItems/PlotItem/PlotItem.py b/pyqtgraph/graphicsItems/PlotItem/PlotItem.py
--- a/pyqtgraph/graphicsItems/PlotItem/PlotItem.py
+++ b/pyqtgraph/graphicsItems/PlotItem/PlotItem.py
@@ -180,7 +180,10 @@ def __init__(self, parent=None, name=None, labels=None, title=None, viewBox=None
         self.dataItems = []
         self.paramList = {}
         self.avgCurves = {}
-        
+        # Change these properties to adjust the appearance of the averged curve:
+        self.avgPen = fn.mkPen([0, 200, 0])
+        self.avgShadowPen = fn.mkPen([0, 0, 0], width=4) # the previous default of [0,0,0,100] prevent fast drawing of the wide shadow line
+
         ### Set up context menu
         
         w = QtGui.QWidget()
@@ -475,8 +478,8 @@ def addAvgCurve(self, curve):
         ### Create a new curve if needed
         if key not in self.avgCurves:
             plot = PlotDataItem()
-            plot.setPen(fn.mkPen([0, 200, 0]))
-            plot.setShadowPen(fn.mkPen([0, 0, 0, 100], width=3))
+            plot.setPen( self.avgPen )
+            plot.setShadowPen(  self.avgShadowPen )
             plot.setAlpha(1.0, False)
             plot.setZValue(100)
             self.addItem(plot, skipAverage=True)


Test patch: