使用 Mathematicia 和 ListPlot 时如何在 List 中指定 x 轴?

编程入门 行业动态 更新时间:2024-10-25 04:15:52
本文介绍了使用 Mathematicia 和 ListPlot 时如何在 List 中指定 x 轴?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我已经用这个 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-25 07:03:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1080300.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   Mathematicia   ListPlot   List

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!