簡體   English   中英

如何在下面的情節中添加圖例?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM