How do I connect points in a scatter plot with a line?
3.177 views (last 30 days)
I plot a scatter for multiple points and i want to connect them using line. Below is my code. The plot i get is only scatter, I cant connect them through a line. Any help appreciated!
Ben11 on 15 Jul 2014
Edited: MathWorks Support Team on 27 Nov 2018
If you want to plot both markers and a line, you can use the plot function and specify a line style that includes marker symbols and a line style, such as '-x'. For example, this code plots a line with crosses at the data points.
If you are trying to plot only the first eight points, then use this code instead:
If you are plotting from a cell array, then use this code instead:
More Answers (2)
John D'Errico on 15 Jul 2014
You asked this question before! In fact, you asked exactly that question, but for some reason nobody managed to give a good answer.
There is NO need for a loop. The above single line will plot x marks at each point, and connect them with a line, all in blue.
If you prefer to plot the line in blue, and the x marks in red, this will do it: