Scattergram

I am making a simple scatterplot:

using Plots
        tk = [1,2,3,5,8]
	y = [1. for i in 1:length(tk)]
	pl = scatter(tk, y, title="Poisson train tk")
	display(pl)

This works. However, I feel that there has to be a more Julian way of accomplishing this task. The comprehension list seems like an unnecessary expense, especially if tk if very large. Thanks.

FWIW, constructing that list will always take negligible time compared to running the plotting.

2 Likes

The comprehension list… it is not quite clear to me why you would make y be equal to 1. for all values of tk, but if that is what you want, here are some other ways:

tk = [1,2,3,5,8]
#y = [1. for i in 1:length(tk)]
#y = ones(length(tk))
function f(t)
    return 1.
end
#pl = scatter(tk, y, title="Poisson train tk")
pl = scatter(tk,f,title="Poisson train tk")

Good point. I could use a lambda function (anonymous function). The following works:

pl = scatter(tk, x->1, title="Poisson train tk")

What I really wanted is a set of points along a horizontal axis at a fixed value of y to clearly see the sequence tk.

If you have another good way of displaying this, I am interested to know what it is. Thanks for the answer!

Gordon