How to plot 1-d data at given y-value with pylab

后端 未结 2 695
忘掉有多难
忘掉有多难 2021-02-06 23:02

I want to plot the data points that are in a 1-D array just along the horizontal axis [edit: at a given y-value], like in this plot:

2条回答
  •  星月不相逢
    2021-02-06 23:36

    This will plot the array "ar":

    import matplotlib.pyplot as pp
    ar = [1, 2, 3, 8, 4, 5]
    pp.plot(ar)
    pp.show()
    

    If you are using ipython, you can start it with the "-pylab" option and it will import numpy and matplotlib automatically on startup, so you just need to write:

    ar = [1, 2, 3, 8, 4, 5]
    plot(ar)
    

    To do a scatter plot with the y coordinate set to 1:

    plot(ar, len(ar) * [1], "x")
    

提交回复
热议问题