NetworkX Bug with Matplotlib

2019-06-03 09:19发布

I've recently reinstalled matplotlib, and I've noticed that code which I'd written some months ago (which was fully functional), which uses networkx to generate a graph output, is now outputting errors on the console. The errors I get are detailed below.

C:\Python36\lib\site-packages\networkx\drawing\nx_pylab.py:126: MatplotlibDeprecationWarning: pyplot.hold is deprecated.
Future behavior will be consistent with the long-time default:
plot commands add elements without first clearing the
Axes and/or Figure.
b = plt.ishold()
C:\Python36\lib\site-packages\networkx\drawing\nx_pylab.py:138: MatplotlibDeprecationWarning: pyplot.hold is deprecated.
Future behavior will be consistent with the long-time default:
plot commands add elements without first clearing the
Axes and/or Figure.
plt.hold(b)
C:\Python36\lib\site-packages\matplotlib\__init__.py:917: UserWarning: axes.hold is deprecated. Please remove it from your matplotlibrc and/or style files.
warnings.warn(self.msg_depr_set % key)
C:\Python36\lib\site-packages\matplotlib\rcsetup.py:152: UserWarning: axes.hold is deprecated, will be removed in 3.0
warnings.warn("axes.hold is deprecated, will be removed in 3.0")
Traceback (most recent call last):
File "C:\Users\lukec\Dropbox\University\Year 2 Semester 2\ICS2210 Data Structures and Algorithms II\Assignment\launcher.py", line 33, in <module>
graph.draw()
File "C:\Users\lukec\Dropbox\University\Year 2 Semester 2\ICS2210 Data Structures and Algorithms II\Assignment\graph.py", line 122, in draw
nx.drawing.nx_pydot.write_dot(G, "graph.dot")   
File "<decorator-gen-232>", line 2, in write_dot
File "C:\Python36\lib\site-packages\networkx\utils\decorators.py", line 220, in _open_file
result = func(*new_args, **kwargs)
File "C:\Python36\lib\site-packages\networkx\drawing\nx_pydot.py", line 43, in write_dot
P=to_pydot(G)
File "C:\Python36\lib\site-packages\networkx\drawing\nx_pydot.py", line 175, in to_pydot
import pydotplus
ModuleNotFoundError: No module named 'pydotplus'

The program still functions correctly however, I get the right calculations and graphic outputs as I did before, the only difference is a different-looking matplotlib:

matplot lib

My question is:

Could this be due to the fact that matplotlib has recently been updated, and networkx seems to be using things from it which are outdated? (Matplotlib was updated last month I believe). Could it be from my code? Is there anything I can do to prevent these errors?

I appreciate any help.

1条回答
该账号已被封号
2楼-- · 2019-06-03 09:50

The date for the newest release of matlplotlib is Feb 20 2017.

The date for the newest release of networkx is Jan 11 2017

Aside from the pydotplus message, the messages you're getting all seem to be warnings that in the near future some current commands won't work (and gives instructions for how to access those future commands right now). I don't know about pydotplus. I don't think it's matplotlib-related.

So yes, this is because of the update. It shouldn't be a problem, but perhaps the next version of networkx will need to work with the new matplotlib.

I believe you will find instructions for getting rid of these warnings at this question: How to suppress matplotlib warning?

查看更多
登录 后发表回答