簡體   English   中英

Matplotlib:刪除單個標記

[英]Matplotlib: Remove Single Marker

我正在嘗試使用matplotlib繪制CDF。 但是,cdfs是從原點開始的,因此我在x和y數組前加了零。 現在的問題是,原點現在被標記為數據點。 我想刪除點(0,0)中的單個標記。

下面的代碼和圖片。

#Part of the myplot (my own) class
def cdf(self):
    markers = ["x","v","o","^","8","s","p","+","D","*"]
    for index,item in enumerate(np.asarray(self.data).transpose()):
        x = np.sort(item)
        y = np.arange(1,len(x)+1) / len(x)
        x = np.insert(x,0,0)
        y = np.insert(y,0,0)
        self.plot = plt.plot(x,
                y,
                marker=markers[index],
                label=self.legend[index])
    self.setLabels( xlabel=self.xlabel,
                    ylabel="cumulative density",
                    title=self.title)
    self.ax.set_ylim(ymax=1)

在此處輸入圖片說明

您無法刪除標記。 您可能要做的是先繪制所有標記,然后附加原點,然后繪制一條線。

x = np.sort(item)
y = np.arange(1,len(x)+1) / len(x)
self.plot, = plt.plot(x, y, marker=markers[index], ls="", label=self.legend[index])
x = np.insert(x,0,0)
y = np.insert(y,0,0)
self.plot2, = plt.plot(x, y, marker="", color=self.plot.get_color())

備選:使用markevery參數。

x = np.sort(item)
y = np.arange(1,len(x)+1) / len(x)
x = np.insert(x,0,0)
y = np.insert(y,0,0)
markevery = range(1, len(x))
self.plot, = plt.plot(x, y, marker=markers[index], markevery=markevery, 
                      ls="", label=self.legend[index])

暫無
暫無

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

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