是否可以在matplotlib的图例中放置多个“标题”?我想要的是这样的:
Title 1
x label 1
o label2
Title 2
^ label 3
v label 4
...
如果我有4条或更多的曲线。因为如果我使用多个图例,则很难手动对齐以正确对齐它们。
我最接近的是创建一个空的代理艺术家。我认为问题在于它们没有对齐,但是(空)标记的空间仍然存在。
from matplotlib.patches import Rectangle
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 1, 100)
# the comma is to get just the first element of the list returned
plot1, = plt.plot(x, x**2)
plot2, = plt.plot(x, x**3)
title_proxy = Rectangle((0,0), 0, 0, color='w')
plt.legend([title_proxy, plot1, title_proxy, plot2],
["$\textbf{title1}$", "label1","$\textbf{title2}$", "label2"])
plt.show()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句