Mathematica 中带有两个数据集的 ListPlot [英] ListPlot With Two Data Sets in Mathematica

查看:51
本文介绍了Mathematica 中带有两个数据集的 ListPlot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有理由保持数据集独立,是否有更简洁的方法来执行以下操作?:

Is there a cleaner way to do the following, assuming that I have a reason to keep the data sets independent?:

x = {1, 2, 3};
y = {1, 4, 9};

ListPlot[Partition[Riffle[x, y], 2]]

谢谢!

推荐答案

我不认为 Timo 的解决方案是标准的.这里有两种方法,使用 TransposeThread,我经常看到使用.

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}]

输出:

{{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.

这篇关于Mathematica 中带有两个数据集的 ListPlot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆