首页 > 解决方案 > 如何在文本框中包含绘图线型图例的图像

问题描述

当我们调用 时legend,该框有一张小图片,显示线条样式/标记样式与我的绘图一起使用。我想获取该图像以进行绘图(实线和虚线的一小部分)并将它们包含在文本框中。

我得到的最接近的是以下内容:

stable, = ax.plot(np.arange(10),np.arange(10),linestyle='solid', linewidth=5,color='k')
unstable, = ax.plot(np.arange(10),np.arange(10),linestyle='dashed', linewidth=3, color='k')
ghost, = ax.plot(0,0) # just to make some space in the legend box
ax.legend([ghost,stable,unstable],['Some text','some text', 'some text',loc='lower left')

但是,对于我想要包含的文本,我认为使用单独的text框并包含我在通常框中看到的“图像”会更容易,legend因为我需要多次引用它。这个怎么做?

标签: pythonmatplotlibtextboxlegend

解决方案


推荐阅读