如何在没有轴和空白的情况下绘制图例

我想创建一个带有一些标签的图例。 我的代码(如下)将所有白色保留在轴的位置(它们是不可见的,但它们在那里)。我只需要保存 图例,不留任何空白(请参见下图)。如果我移除轴,则图例也消失了。

import matplotlib.pyplot as plt
import seaborn as sns
import itertools

fig = plt.figure()
ax = fig.add_subplot(111)

palette = itertools.cycle(sns.color_palette())

labels = ['a','b','c']
lines = []
for i in labels:
    ax.plot(0,color=next(palette),linewidth=3,linestyle='--')

leg = plt.legend(ax.lines,labels)

ax.axis("off")

plt.savefig("legend.pdf",bbox_inches='tight',pad_inches=0)

如何在没有轴和空白的情况下绘制图例

a840866712 回答:如何在没有轴和空白的情况下绘制图例

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3043489.html

大家都在问