So I have been playing with pyqtgraph and I came to a problem where I needed to add strings as x axis tick label (instead of default float). So I looked around and found Show string values on x-axis in pyqtgraph
The solution kind of does what I need to do (the first solution on the page, the second one will cause problems because I am on python 3.5). So I tried to modified the first solution, but it did not work.
from PyQt4 import QtCore
import pyqtgraph as pg
x = ['a', 'b', 'c', 'd', 'e', 'f']
y = [1, 2, 3, 4, 5, 6]
xdict = dict(enumerate(x))
win = pg.GraphicsWindow()
stringaxis = pg.AxisItem(orientation='bottom')
stringaxis.setTicks([xdict.items()])
plot = win.addPlot(axisItems={'bottom': stringaxis})
curve = plot.plot(xdict.keys(),y)
if __name__ == '__main__':
import sys
if sys.flags.interactive != 1 or not hasattr(QtCore, 'PYQT_VERSION'):
pg.QtGui.QApplication.exec_()
The error I am getting is TypeError: 'dict_keys' object does not support indexing on line
curve = plot.plot(xdict.keys(),y)
I tried turning it into a list, by doing it as follows:
curve = plot.plot(list(sdict.keys(),y))
but this made the output has a small problem
The problem is that there is another axis added to the top left of the plot. Can someone tell me what I am doing wrong here?