使用 Mathematicia 和 ListPlot 时如何在 List 中指定 x 轴? [英] How to specify x-axis in List when using Mathematicia and ListPlot?

查看:24
本文介绍了使用 Mathematicia 和 ListPlot 时如何在 List 中指定 x 轴?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用这个 stmt 将一个 csv 文件导入到一个列表中:

I have imported a csv file into a list with this stmt:

data1 = Take[Import["D:\\_reports\\optim_5_60_b_2.csv", "CSV"],   5]

给出:

{{178, 8, 9, 1}, {152, 2, 8, 1}, {378, 8, 9, 2},
 {343, 3, 7.5`, 2}, {143, 3, 7.5`, 1}}

我想创建一个图,其中 x 轴基于第一个字段:

I would like to create a plot where the x-axis is based on the first field:

178,152,378,343,143,373,743,352

178,152,378,343,143,373,743,352

该图为每个后续字段创建一条线,因此第二个字段是:

And the plot creates a line for each subsequent field, so the 2nd field is:

8,2,8,3,3,3,3,2

8,2,8,3,3,3,3,2

这将是 y 轴上的第一条线,其他 y 轴值将以相同的方式绘制.我希望第一个 y-plot 用红色绘制,第二个用蓝色绘制,第三个用绿色绘制.

This would be the first line on the y-axis, the other y-axis values would be plotted in the same manner. I would like the first y-plot to be plotted in red, and the second in blue, and the third in green.

推荐答案

还有一个替代版本:

data = {{178, 8, 9, 1}, {152, 2, 8, 1}, {378, 8, 9, 2},
   {343, 3, 7.5, 2}, {143, 3, 7.5, 1}};

x = data[[All, 1]];

ListLinePlot[
 Transpose[
  Sort[MapThread[Function[xpt, {xpt, #} & /@ #2][#1] &,
    {x, Rest /@ data}]]], PlotStyle -> {Red, Blue, Green},
 PlotMarkers -> {Automatic, 10}, AxesOrigin -> {Min@x, Automatic}]

类似,但更易于阅读:

ListLinePlot[
 Transpose[
  Sort[Table[Map[{data[[i, 1]], #} &, Rest[data[[i]]]],
    {i, Length[data]}]]], PlotStyle -> {Red, Blue, Green},
 PlotMarkers -> {Automatic, 10}, AxesOrigin -> {Min@x, Automatic}]

这篇关于使用 Mathematicia 和 ListPlot 时如何在 List 中指定 x 轴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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