Use Line2D to plot line in python

后端 未结 3 1482
予麋鹿
予麋鹿 2021-01-02 10:08

I have the data:

x = [10,24,23,23,3]
y = [12,2,3,4,2]

I want to plot it using

matplotlib.lines.Line2D(xdata, ydata)

I use

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-02 10:19

    I have run into this problem when trying to replicate a line on two different plots. (mentioned in a comment "cannot put single artist in more than one figure) So assuming you already have a Line2D object from some other source and need it on new plot, the best way to add it to your plot is with:

    # the variable, 'line', is assumed to be a Line2D object.
    plt.plot(*line.get_data(), ...)
    

    You can also get a lot of the line's properties from its other "get" methods, found here.

提交回复
热议问题