Message Boards Message Boards

GROUPS:

plotting an array of dataset with ListPlot

Posted 10 years ago
4775 Views
|
3 Replies
|
1 Total Likes
|
hi, I have a set of datapoints such as
val=3; (*this value is calculated before in the program, so it not known a priori*)
x={0,1,2,3};
data = Table[0, {val}];
For[i = 1, i < val + 1, i++,
data[[i]] = x+i];
Now I can plot each of these data with ListPlot as
ListPlot[Transpose[{x,data[[1]]}]]
and if I want to plot more than one I can do
ListPlot[{Transpose[{x, data[[1]]}], Transpose[{x, data[[2]]}]}]
but how can I plot all of them in one code single line, by considering that val is calculated before in the program
Is there a way to do something like
For[i = 1, i < val + 1, i++, ListPlot[Transpose[{x,data[]}]]......]?

I was thinking about the use of Show and overlap the graphs, but probably there is an easier solution

Any tutorial added to the answer is more than welcome
Thanks
Smazzu
POSTED BY: S Mazzu
3 Replies
Hi,
  x = {0, 1, 2, 3};
 
 (* do not use For or Do unless it's completely unavoidable *)
 data = Table[x[[i]] + i, {i, 1, Length[x]}];
 (* note now x and data have the same length *)
 Length[x]
 Length[data]
 (* you can transpose only lists of an equal length *)
 Transpose[{x, data}]
(* it's ready to plot *)
ListPlot[%]
(* use Show[] for different types of graphics *)
Not sure about a complete tutorial, but F1 can help, at least simple examples can be found there.
Also try to search the web for solutions, many problems are already solved.

I.M.
POSTED BY: Ivan Morozov
Posted 10 years ago
Thanks but indeed it is not the answer to my problem.
I need to plot all the data in different curves but in the same graph
{{1, 2, 3, 4}, {2, 3, 4, 5}, {3, 4, 5, 6}}
with x as common axis
At the end I want to have a graph with val=3 curves, a kind of static way to plot
Manipulate[ListPlot[Transpose[{x, data[[i]]}]], {i, 1, val,1}]

Thanks
Smazzu
POSTED BY: S Mazzu
Posted 10 years ago
I thought I found the solution with
ListPlot[Insert[data,x,1]]
but the x value is not the right one
Smazzu
POSTED BY: S Mazzu
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract