2
我想繪製一個圖例,指定標記的值和線的值,但不是兩者的組合。圖例中的分割標記和線 - Matplotlib
這個例子應該有助於說明我的目標:
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