PyQtGraph errors in Spyder/IPython

I get an error when adding titles / labels with specific colors and/or font sizes. Even running the example code leaves me with problems. I use Python 3.7.3 (through Spyder, iPython 7.6.1).

This line:

self.graphWidget.setTitle("Your Title Here", color='blue', size=30)

leads to:

File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\functions.py", line 182, in mkColor
g = int(c[1]*2, 16)
ValueError: invalid literal for int() with base 16: 'll'

Changing the color to ‘black’ strangely leads to:

File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\functions.py", line 222, in mkColor
args = [r,g,b,a]
UnboundLocalError: local variable 'r' referenced before assignment

When removing the color argument, I get:

File "C:\ProgramData\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\LabelItem.py", line 61, in setText
optlist.append('font-size: ' + opts['size'])
TypeError: can only concatenate str (not "int") to str

Since obviously your code seems to work on the website and in the examples, is this Spyder / iPython related? And if so, how could I solve this?

I also could not run the code as is. I have version Python 3.8.1 and am running on Windows 10. I first loaded 0.11.0rc0 to get rid of the time.clock error mentioned earlier.

The Title error happens because of the way the color is called (color=‘blue’). if you look at functions.py, it is not expecting ‘blue’. If you just make that ‘b’, it will get past that error. In my case, I altered functions.py by adding some if statements to convert any color that is completely spelled out to the appropriate single color letter, like blue = b, red = r, green=g, black = k, and so on. This solved the problem and actually permits any color full name to be used. Below is the code correction for the color blue in functions.py. Repeat this for green, yellow, red, ….

if args[0] == 'blue':
    argslist=list(args)
    argslist[0]='b'
    args=tuple(argslist)
    print("args set to: ", args)

Next you need to correct LabelItem.py. In the example, they call size=30. LabelItem.py expects this to be 30pt in the setText definition. So I corrected the program by adding if opts[‘size’].endswith(“pt”):. Using a try/except around this, it will give an AttributeError if “pt” is not there. So I then added the line: opts[‘size’]=str(opts[‘size’])+“pt” under the exception to set opts to the appropriate value. These two items will allow the program to run. Note that this is within the if statement if ‘size’ in opts (starts at line 60) of the LabelItem.py script. Here is the working code in setText of LabelItem.py.

if ‘size’ in opts:
try:
if opts[‘size’].endswith(“pt”):
print(“ends with pt”)
except AttributeError:
opts[‘size’]=str(opts[‘size’])+“pt”
pass
optlist.append('font-size: ’ + opts[‘size’])

I just ran into another error… adding the additional code to allow the data to scroll. This gives me the error Typeerror: ‘builtin_function_or_method’ object is not subscriptable. The line self.x[0]… is the culprit. If I find the cause of this error, I will post it.