Unresolved attribute reference, simple matplotlib usage
Answered
In a very basic bit of example code, PyCharm is generating a warning "Unresolved attribute reference" and of course this means code completion also does not work. The code is perfectly functional however and runs as expected. I'm sure I'm missing something obvious...
import matplotlib.pyplot as plt
ax = plt.subplot()
ax.plot([1, 2], [3, 4])
plt.show()
The warning highlight is on 'plot' of 'ax.plot' - but setting a breakpoint on that line and using the Evaluate Expression dialog reveals that ax is of type AxesSubplot, which does have a plot() method. Why does PyCharm miss the reference?
Please sign in to leave a comment.
Hi,
Thank you for contacting PyCharm support.
Have you tried `File | Invalidate Caches / Restart...`?
Please attach a screenshot demonstrating the problem and also a screenshot of your Project Interpreter window.
Kind regards,
Sergey
I did, thanks for responding. It's basically the first thing I try whenever I'm resolving these kinds of issues.
Steps I took so far:
- update and restart PyCharm (only needed some plugin updates, no major plugins installed)
- invalidate caches and restart
- create a new project and environment and install nothing but the current version of matplotlib (and dependencies) from PyPI using pip install
All this is using Python 3.6.4 64-bit, matplotlib 3.0.0 and PyCharm 2018.2.4 Pro (on Windows 10).
I asked here since I hoped some community member could point out the obvious before I go and submit a ticket on the tracker. I you prefer I submit a ticket, please do let me know.
I've included the screenshot you requested.
Regards, JAAP.
Thanks for the update.
It seams to be related to https://youtrack.jetbrains.com/issue/PY-32025, please vote for it and follow for updates. See https://intellij-support.jetbrains.com/hc/en-us/articles/207241135-How-to-follow-YouTrack-issues-and-receive-notifications if you are not familiar with YouTrack.
It is resolved when using matplotlib 2.2.3
Kind regards,
Sergey
You're right - it does appear to be a duplication of that issue, apologies for not looking hard enough for it there. I've applied the workaround there and will check in the future if newer versions of PyCharm (or matplotlib) resolve the issue.
I need some of the new features of 3.0.0, so using 2.2.3 isn't an option for me, but I was able to verify that this also resolved / circumvented the issue.
I'm using matplotlib 3.1.2 and I still face the issue:
@Saravanabalagi
Unfortunately, the issue is not addressed yet https://youtrack.jetbrains.com/issue/PY-32025
I am also using matplotlib vers 3.1.2 and also have a similar issue:
Any updates on this?