0

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 problemplot window with 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?

Community
  • 1
  • 1
A Saxena
  • 165
  • 2
  • 13

1 Answers1

0

Well I was not sure if I could answer my own question so I looked it up and found https://stackoverflow.com/help/self-answer. So here is the answer.

Go to pyqtgraph google group https://groups.google.com/forum/#!searchin/pyqtgraph/string|sort:relevance/pyqtgraph/pSIn0xNGodA/79pR3dUBLAAJ and look for a question from Upol Ryskulova. He is asking the exact same question. The responses to that comment confirm that it is a bug in pyqtgraph. It has been fixed but the fix has not yet propagated to my anaconda distribution. So what I need to do is wait for some time and that bug will go away. The fix is also discussed in the group, and there is nothing wrong with he code.

Community
  • 1
  • 1
A Saxena
  • 165
  • 2
  • 13