图例句柄中的圆圈在 matplotlib 中不起作用

Circle in the legend handle doesn't work in matplotlib

我在 Ubuntu 18.04,我的 matplotlib 版本是 2.1.1。我正在尝试将圆形补丁绘制为图形图例句柄。 This example 提供了一种使用自定义句柄的方法,如下所示:

import matplotlib.patches as mpatches
import matplotlib.pyplot as plt

red_patch = mpatches.Patch(color='red', label='The red data')
plt.legend(handles=[red_patch])

plt.show()

但我想要一个圆形手柄而不是矩形贴片。所以我尝试了:

将 matplotlib.pyplot 导入为 plt 导入 matplotlib.patches 作为 mpatches

fig, ax = plt.subplots(1, 1)
circle = mpatches.Circle(xy = (0.5, 0.5), radius = 100,color = "green")

ax.plot([1, 2, 3], [1, 2, 3])

fig.legend(handles = [circle], labels = ["some funny label"])
plt.show()

但是,我仍然得到一个矩形补丁,而且在我看来,位置错误。我到底错过了什么?

Edit : 我特意问一下我的代码有什么问题。有变通办法是有帮助的,但我没有发现上面的代码有任何问题。

docs 他们这样做如下:

from matplotlib.lines import Line2D
import matplotlib.pyplot as plt

red_circle = Line2D([0], [0], marker='o', color='w', label='Circle',
                        markerfacecolor='r', markersize=15),
plt.legend(handles=red_circle)