Search code examples
pythonmatplotlibversionlegend

matplotlib.legend - `ncols` not recognized - version compatibility problem?


I have a python script using matplotlib and the function legend to which I pass the option ncols. In itself, it is not a problem and run very well on my computer but it does not work for my colleagues who get the following error:

TypeError: __init__() got an unexpected keyword argument 'ncols'

I noticed that I am using Matplotlib version 3.6.2 while my colleagues are using Matplotlib version 3.4.2.

Could someone tell me if the option ncols was added or changed made to it in between Matplotlib version 3.4.2 and 3.6.2?

I could not find this information in Matplotlib release notes but I noticed on the matplotlib.legend documentation the following:

"For backward compatibility, the spelling ncol is also supported but it is discouraged. If both are given, ncols takes precedence."

It makes me think that my colleagues impossibility to run the code might be linked to some ncols update.


Solution

  • You basically found it. If you look on the API for 3.4 and 3.5, the parameter was ncol with no s. The note in 3.6 (Stable) means that it still supports ncol but will prefer and overwrite if you use ncols. If you want to maintain usage across you and your colleague's different Matplotlibs, just use ncol.