[英]How to add legend to below plot?
试图将图例添加到线图但无法做到。 请建议一些方法或解决方案。
counts, bin_edges = np.histogram(df_status_1['nodes'], bins=10,
density = True)
pdf = counts/(sum(counts))
print(pdf);
print(bin_edges);
cdf = np.cumsum(pdf)
plt.plot(bin_edges[1:],pdf);
plt.plot(bin_edges[1:], cdf)
counts, bin_edges = np.histogram(df_status_2['nodes'], bins=10,
density = True)
pdf = counts/(sum(counts))
print(pdf);
print(bin_edges);
cdf = np.cumsum(pdf)
plt.xlabel('nodes');
plt.ylabel('values');
plt.title('CDF of long & short surviving ppl');
plt.plot(bin_edges[1:],pdf);
plt.plot(bin_edges[1:], cdf)
试图添加 plt.legend() 但得到“没有找到放置在图例中的标签的句柄”错误。在此处输入代码
将每个 plt.plot 存储到一个带有 coma 的轴(plt.plot 返回元组)
前任:
arr1, = plt.plot(bin_edges[1:],pdf);
arr2, = plt.plot(bin_edges[1:], cdf)
plt.legend([arr1,arr2], ['PDF survived','CDF survived'])
像上面一样尝试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.