I am working on some python codes in PyCharm IDE. The autocomplete feature works fine in some cases, but not the others. For example, after I import matplotlib as plt, after I type "plt.", all possible methods shows below

However, some variables do not seem to have autocomplete. If I type the methods manually, the program works fine. But the IDE just does not prompt me what methods are available to the variable. It shows something starting with "__", but not methods that I am supposed to use. For example, after I create ax1 = plt.subplot2grid((1,1), (0,0)), I can invoke tick_params method on ax1 variable. It is a valid method. However, this method does not show up in the list when I type "ax1."

I don't think this problem is specific to PyCharm. I have run into the similar issue in other Python IDE or Python Notebook in the past. What am I missing here?
autocomplete can only help you with classes ... that is a method that you are calling to get the axes object
consider
def get_something():
if caseA: return Something1()
return DefaultSomething()
pycharm(or any ide) has no idea which class would be returned its either one of those or maybe nothing ... what should it give you as autocomplete?
that said you can tell pycharm it must be of type matplotlib.Axes
ax1 = plt.subplots(....)
assert isinstance(ax1,matplotlib.Axes)
ax1. # now autocomplete works
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With