【发布时间】:2015-12-31 23:00:33
【问题描述】:
我想制作一个图例,在其中指定标记的值和线条的值,但不指定两者的组合。
这个例子应该有助于说明我的目标:
import matplotlib.pyplot as plt
import numpy as np
pi=3.14
xx=np.linspace(0,2*pi,100)
fig = plt.figure()
ax = fig.add_subplot(111)
phases=[0,pi/4,pi/2]
markers=['s','o','^']
for phase,mk in zip(phases,markers):
labeltext='Sine' + '*' + str(phase)
F=[np.sin(x+phase) for x in xx]
ax.plot(xx,F,color='b',marker=mk,label=labeltext)
labeltext='Cosine' + '*' + str(phase)
F=[np.cos(x+phase) for x in xx]
ax.plot(xx,F,color='g',marker=mk,label=labeltext)
hand, labl = ax.get_legend_handles_labels()
#hand, labl = function_to_split(hand,labl,'*')
ax.legend(hand,labl)
plt.savefig('Figure.png')
我想要的是 function_to_split 自动以这样的图例结束:
[blue line] Sine
[green line] Cosine
[black square] 0
[black circle] 0.785
[black triangle] 1.57
【问题讨论】:
标签: python matplotlib legend