# How can I make ListPlot output a graphic in Mathematica 9?

Posted 9 years ago
3254 Views
|
3 Replies
|
0 Total Likes
|
 Dear AllI'm new to this forum, so apologies if this is the wrong place for my question and/or it's been asked before.I'm using Mathematica 9, and I'm having some trouble with the ListPlot function. For example, say I execute this code: data1 = {0.1, 0.4, 0.3}; ListPlot[data1, Joined -> True] then I get a nice little plot in my notebook. But say I execute this code instead: data1 = {0.1, 0.4, 0.3}; ListPlot[data1, Joined -> True]; data2 = {0.2, 0.3, 0.4}; ListPlot[data2, Joined -> True] then it only gives me the second plot (i.e. data2), rather than the two plots (i.e. data1 & data2).In previous versions of Mathematica (version 5, perhaps?), this code would have returned two plots (or, rather, it would if I used PlotJoined rather than Joined). The context is that I want to use a single line of code, with a Do function, to return several plots of data, each dataset being generated by a separate iteration of the Do function. But even something as simple as: data = {0.1, 0.4, 0.3}; Do[ListPlot[data, Joined -> True], {10}] is not doing what I want it to. I'd be grateful for any advice on this issue.Best wishesAndy
3 Replies
Sort By:
Posted 9 years ago
 Thank-you Nasser & Bill -- that's solved my problem.Best wishesAndy
Posted 9 years ago
 Try this data2 = {0.2, 0.3, 0.4}; Print[ListPlot[data1, Joined -> True]]; data1 = {0.1, 0.4, 0.3}; Print[ListPlot[data2, Joined -> True]] and this data = {0.1, 0.4, 0.3}; Do[ Print[ListPlot[data, Joined -> True]], {10}] 
Posted 9 years ago
 Inside Do need to use Print to get the output to display. Also ";" suppresses output that is why you do not see the plot in the first case. For the loop, you can try data = {0.1, 0.4, 0.3}; p = Last@Reap[Do[Sow@ListPlot[data, Joined -> True], {10}]]; Grid[p]