…end..."], but never being used in the call to FancyBboxPatch
The documentation stated that the default legend position was 0, corresponding to "best". This does not match the behavior of the current code, which uses as default the rcParam value "legend.loc", which at time of writing defaults to "upper-right".
Change to using a helper function and isinstance(path, bytes) to decode __file__ based on file system encoding.
When my py file importing matplotlib run in a folder where the path contains gbk encoding character, matplotlib will raise a unicode decode error.The changes in line 666/673/679 will fix the problem.