matplotlib图例的标题

2024-05-15 23:35:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我知道给一个传说起一个标题似乎是相当多余的,但是有没有可能使用matplotlib呢?

下面是我的一段代码:

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

one = mpatches.Patch(facecolor='#f3f300', label='label1', linewidth = 0.5, edgecolor = 'black')
two = mpatches.Patch(facecolor='#ff9700', label = 'label2', linewidth = 0.5, edgecolor = 'black')
three = mpatches.Patch(facecolor='#ff0000', label = 'label3', linewidth = 0.5, edgecolor = 'black')

legend = plt.legend(handles=[one, two, three], loc = 4, fontsize = 'small', fancybox = True)

frame = legend.get_frame() #sets up for color, edge, and transparency
frame.set_facecolor('#b4aeae') #color of legend
frame.set_edgecolor('black') #edge color of legend
frame.set_alpha(1) #deals with transparency
plt.show()

我想要标签1上面的传说的标题。作为参考,这是输出: Showing legend


Tags: import标题matplotlibpltframelabelpatchcolor