Set markers for individual points on a line in Matplotlib

前端 未结 4 918
慢半拍i
慢半拍i 2020-11-27 08:49

I have used Matplotlib to plot lines on a figure. Now I would now like to set the style, specifically the marker, for individual points on the line. How do I do this?

<
4条回答
  •  感情败类
    2020-11-27 09:44

    A simple trick to change a particular point marker shape, size... is to first plot it with all the other data then plot one more plot only with that point(or set of points if you want to change the style of multiple points). Suppose we want to change the marker shape of second point:

    x = [1,2,3,4,5]
    y = [2,1,3,6,7]
    
    plt.plot(x, y, "-o")
    x0 = [2]
    y0 = [1]
    plt.plot(x0, y0, "s")
    
    plt.show()
    

    Result is: Plot with multiple markers

提交回复
热议问题