使用表中的一列作为 x 值,其他列作为 y 值绘制 [英] Plot using one column from a table as the x-value, other columns as y-values

查看:35
本文介绍了使用表中的一列作为 x 值,其他列作为 y 值绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个矩阵,第一列是时间,第二列是 A 的位置,第三列是 B 的位置,等等.我想绘制 A、B、...的位置.,作为时间的函数,在同一张图中.在 Mathematica 中,是否有比逐列绘制绘图然后通过显示"组合它们更有效的方法?

I have a matrix, the first column being the time, and the second column being the position of A, the third column the position of B, etc. I would like to plot the positions of A, B, ..., as functions of the time, in the same figure. Is there a more efficient way in Mathematica than making the plots column by column and then combining them by "Show"?

另外,我希望这些图的颜色自动选择为彼此不同;为了让这种自动化有用,同时会自动生成图例.如何在 Mathematica 中做到这一点?

Also, I would like the plots have their colors automatically chosen to differ from each other; to let this automation useful, a legend is automatically generated at the same time. How to do this in Mathematica?

谢谢!

[更新]:Chris 的方法非常有效.但是默认的图例使用了颜色有点难分辨的小圆点;此外,似乎只有 4 种颜色;就我而言,有 ~20 个 y 值,这使得图例实际上毫无用处.是否还有其他更大、颜色更多的符号(例如,一些灰度或连续变化的颜色)?

[update]: Chris' method works extremely well. But the default legend uses small dot whose colors are a bit difficult to tell; also, there seems to be only 4 colors; in my case there are ~20 y-values, making the legend effectively useless. Are there other symbols that are bigger, and with more colors (e.g., some grayscales or continuously varying colors)?

推荐答案

a = {{{2001, 1, 1}, 2, 3, 4},
     {{2002, 1, 1}, 3, 4, 5},
     {{2003, 1, 1}, 4, 5, 6},
     {{2004, 1, 1}, 5, 6, 7},
     {{2005, 1, 1}, 6, 7, 8}};

DateListPlot[MapThread[Transpose[{#1, #2}] &,
  {Table[First /@ a, {Length@Rest@Last@a}], Transpose[Rest /@ a]}],
 Joined -> True, PlotLegends -> {"A", "B", "C"}]

这篇关于使用表中的一列作为 x 值,其他列作为 y 值绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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