Mathematica How Can I Generate and Plot Multiple Y Sets in Mathematica?

AI Thread Summary
To plot a set of Y points against a corresponding set X in Mathematica, one can use the Transpose function to create a paired dataset. For example, given Y = {1, 5, 4}, the command XY = Transpose[{Y, Range[Length[Y]]}] generates the pairs needed for plotting. The resulting dataset can then be visualized using ListPlot with the option PlotJoined->True.When Y is generated dynamically within a loop, and there is a need to retain the previous plot while updating Y, Mathematica does not have a direct equivalent to MATLAB's HoldOn function. Instead, users can utilize the Show function to combine multiple plots into a single visualization. This allows for the retention of the original plot while overlaying new data generated in subsequent iterations.
brydustin
Messages
201
Reaction score
0
Suppose that I had a set of Y points Y = {y1,y2,...yN} and I want to plot them again a set X = {1,2,3,...,N}

Naturally, I would like to do something like:
YX = { {y1, 1} , {y2,2} , ... , {yN,N} }
followed by
ListPlot[YX,PlotJoined->True]


My question is: How can I construct YX in a very simple manner?
 
Physics news on Phys.org
In[1]:= Y={1,5,4}; XY=Transpose[{Y,Range[Length[Y]]}]

Out[2]= {{1,1},{5,2},{4,3}}
 
Thanks...
But what if the set Y was generated in a loop by some arbitrary means, and I wanted to plot Y, and then trash its values, hold the plot, rerun the calculation generating a new Y, and then plot it along with the first Y, keeping the same domain (X).
I know in MATLAB we would use the HoldOn function, but is there something like this in mathematica?
 

Similar threads

Replies
4
Views
2K
Replies
3
Views
7K
Replies
3
Views
2K
Replies
6
Views
2K
Replies
1
Views
2K
Replies
3
Views
6K
Back
Top