【发布时间】:2023-04-01 11:44:01
【问题描述】:
我知道为图例设置标题似乎是多余的,但是否可以使用 matplotlib?
这是我拥有的代码的 sn-p:
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()
【问题讨论】:
-
出于兴趣,你能告诉你是什么原因让你问这个问题吗?花了很多精力来写它,甚至放一张图片,而不仅仅是谷歌matplotlib legend title之类的东西或看文档?
-
-
我喜欢第一句话“我知道给传奇起个头衔似乎是多余的”——好主意。
标签: python matplotlib patch