簡體   English   中英

如何在情節中將相同的圖例(標簽)設置為不同的散點?

[英]How to set the same legend (Label) to different scatter points in my plot?

需要一些使用matplotlib / pylab處理圖例的指南。

for xe, ye in zip(dist, liston):
    plt.scatter([xe] * len(ye), ye, s = 200, color = 'darkseagreen')

哪里:

dist = [2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0, 18.0, 20.0]
liston = [[-46.6, -46.7, -53.0], [-52.4, -50.7, -51.0], [-54.2, -54.0, -52.8], [-53.3, -51.4, -54.2], [-56.8, -54.4, -52.4], [-55.5, -54.9, -55.7], [-59.1, -59.4, -57.0], [-58.4, -54.8, -58.8], [-56.7, -55.5, -62.3], [-56.2, -57.5, -59.1]]

我的繪圖現在具有按距離的點(liston x dist),誤差線和每距離的度量平均值(x軸)。 我有一個錯誤和均值已啟動並正在運行的圖例,但我未能通過分散點來實現。

由於我是在循環中運行散點圖,因此如果嘗試在其中進行標記,我將得到10個相同的圖例,這不是我想要的(需要將我的10個散點圖視為一個)。

任何見解都會有所幫助!

謝謝你的時間。

我將擺脫循環並繪制單個散點圖。

import matplotlib.pyplot as plt
import numpy as np

dist = [2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0, 18.0, 20.0]
liston = [[-46.6, -46.7, -53.0], [-52.4, -50.7, -51.0], [-54.2, -54.0, -52.8], 
          [-53.3, -51.4, -54.2], [-56.8, -54.4, -52.4], [-55.5, -54.9, -55.7], 
          [-59.1, -59.4, -57.0], [-58.4, -54.8, -58.8], [-56.7, -55.5, -62.3], 
          [-56.2, -57.5, -59.1]]

y = np.array(liston).T
x = np.tile(dist, len(y))

plt.scatter(x, y, s = 200, color = 'darkseagreen', label="MyLabel")
plt.legend()

plt.show()

暫無
暫無

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

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