【问题标题】:How to add 'one-to-one' legend to each plot line (matplotlib in Python)如何为每条绘图线添加“一对一”图例(Python 中的 matplotlib)
【发布时间】:2017-04-10 19:17:16
【问题描述】:
fig = plt.figure()
ax1 = fig.add_subplot(111)

ax1.plot(hpi_data, label = hpi_data.columns.values) #<-- how to add values to each plot?
ax1.plot(benchmark, linewidth=3, label='Benchmark')

plt.legend(loc=2, ncol=2, prop={'size':12}).get_frame().set_alpha(0.1)
plt.show()

请看传说,它看起来有点乱。有谁知道如何将每个标签相应地分配给每个情节?

【问题讨论】:

标签: python matplotlib legend subplot


【解决方案1】:

我不确定这是否是您要寻找的,但我对每个情节都有明确的分配:

f = plt.figure(1)
plt.plot(packages, pk_dictionary.get(4), 'o-', label='delta 4')
plt.plot(packages, pk_dictionary.get(18), 'o-', label='delta 18')
plt.legend(loc='upper right')
plt.title("Probabilities")
plt.xlabel("Package amounts")
plt.ylabel("Probability")
f.show()

【讨论】:

    猜你喜欢
    • 2013-05-17
    • 2023-03-04
    • 1970-01-01
    • 2022-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    相关资源
    最近更新 更多