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])