简体   繁体   English

Matplotlib:删除单个标记

[英]Matplotlib: Remove Single Marker

I'm trying to plot a cdf with matplotlib. 我正在尝试使用matplotlib绘制CDF。 However, cdfs begin in the origin, thus I prepended zeros to the x and y arrays. 但是,cdfs是从原点开始的,因此我在x和y数组前加了零。 The problem is now that the origin now is marked as a data point. 现在的问题是,原点现在被标记为数据点。 I'd like to remove that single marker in the point (0,0). 我想删除点(0,0)中的单个标记。

Code and picture below. 下面的代码和图片。

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

在此处输入图片说明

You cannot remove a marker. 您无法删除标记。 What you may do is to plot all the markers first, then append the origin and then plot a line. 您可能要做的是先绘制所有标记,然后附加原点,然后绘制一条线。

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

Alternative: Use the markevery argument. 备选:使用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