ListPlot With Two Data Sets in Mathematica

二次信任 提交于 2019-12-03 20:16:36
Davorak

I do not think Timo's solution is standard. Here are two methods, using Transpose or Thread, that I have often seen used.

x = {1, 2, 3};
y = {1, 4, 9};
Transpose[{x, y}]
Thread[{x, y}]

Output:

{{1, 1}, {2, 4}, {3, 9}}
{{1, 1}, {2, 4}, {3, 9}}

Both of these methods avoid explicitly referencing the length of your data which is plus in my book.

ListPlot[Transpose[{x, y}]]

ListPlot[{x,y}]

EDIT: @Davorak: it certainly will. If OP wants 'y against x' then

ListPlot[y]

would suffice. Either way, I don't understand the complicated answers to a very simple question. But then, I don't understand a lot of the questions on SO.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!