簡體   English   中英

Matplotlib Plot 中的額外圖例

[英]Extra Legend in Matplotlib Plot

我有 matplotlib 從數據創建的圖例,但我想添加一個額外的圖例以及我需要包含的其他一些信息。 我怎樣才能做到這一點?

我是 Python 的新手,我閱讀了幾個論壇,但我找不到任何東西

You need to manually add the different legend to your plot. You can add more than one legend to your plot using.add_artist。

data1 = plt.scatter([1, 2, 3],[3,2,1])
data2 = plt.scatter([4,6,7],[3,2,8])

# Create a legend
legend_1 = plt.legend(handles=[data1])

# Add the legend to the current Axes.
ax = plt.gca().add_artist(legend_1)

# Create another legend for the second line.
plt.legend(handles=[data2])

有關圖例指南的更多信息: https://matplotlib.org/3.3.3/tutorials/intermediate/legend_guide.html#multiple-legends-on-the-same-axes

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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