I'm using pyqtgraph to create scatter plots, when I create a scatterplot like this:
scatter = pg.ScatterPlotItem([1,2,3,4], [1,2,3,4], symbol='x', brush='r', size=10)
then I get the expected behavior (crosses):
The only issue with this version of creating a scatter plot is that I can't control the color of each individual symbol (this ability is necessary for my project). I did a bit of research and I came across a way to specify details of each individual data point using a dictionaries.
Here's my code:
import sys
from PyQt5 import QtWidgets
import pyqtgraph as pg
app = QtWidgets.QApplication(sys.argv)
graph = pg.PlotWidget()
orderScatterDict = []
for i in range(4):
color = 'b'
if i % 2 == 1:
color = 'r'
#change the time to be what it actually is
spot_dic = {'pos': (i, i), 'size': 10, 'symbol':'x',
'pen': {'color': color, 'width': 10}}
orderScatterDict.append(spot_dic)
scatter = pg.ScatterPlotItem() #scatter = pg.ScatterPlotItem([1,2,3,4], [1,2,3,4], symbol='x', brush='r', size=10)
graph.addItem(scatter)
scatter.setData(orderScatterDict)
graph.show()
app.exec_()
However when I do this, the symbols are all squares:
Any idea why this is happening?
Your pen width
is the same as the size
of the crosses, resulting in fat crosses that almost look like squares. Change width
to something smaller (or remove it completely), and you will see the crosses again.