英文:
Plotting multiple curves every end of a sequence of a third different column from 2 plotted columns
问题
I can help with the translation, but it's important to note that translating code instructions might not be straightforward, as code-specific terms may not have direct equivalents in Chinese. Here's the translation of the provided content:
我不知道如何绘制多条曲线,每条曲线在每个序列之后开始和结束。我的序列会重复自己 "N" 次(多次),从 1 到 5。我想要绘制 column2 相对于 column3 的图表,并且每次 column1(使用它作为三元运算符)从 1 到 5 时都有不同的曲线。
在示例中,应该生成一个带有 2 条曲线的图表。序列本身是一个变量,不是固定数量的点。
例如:
column1 column2 column3
1 1 2 4
2 1 3 6
3 1 5 7
4 1 9 0
5 2 5 7
6 2 8 9
7 3 9 6
8 4 4 3
9 4 2 4
10 4 6 9
11 4 0 0
12 5 7 0
13 5 6 8
14 1 5 2
15 2 3 5
16 3 6 7
17 4 8 3
18 4 2 1
19 4 2 6
20 5 8 9
使用线点会是最好的选择,但使用点也很好。颜色不重要,无需添加图例。
英文:
I can't figure how to plot multiple curves which start and ends after every sequence. My sequences repeats itself for "N" times (many) from 1 to 5. I want to plot column2 versus column3 and have a different curve each time column1 (using it as ternary operator) goes from 1 to 5.
In the eample it should come out a graph with 2 curves. The sequence is a variable itself it's not a constant number of points.
for example:
column1 column2 column3
1 1 2 4
2 1 3 6
3 1 5 7
4 1 9 0
5 2 5 7
6 2 8 9
7 3 9 6
8 4 4 3
9 4 2 4
10 4 6 9
11 4 0 0
12 5 7 0
13 5 6 8
14 1 5 2
15 2 3 5
16 3 6 7
17 4 8 3
18 4 2 1
19 4 2 6
20 5 8 9
Linepoints would be the best, but with points it also very good. The colour is not important, there is no need to have a key.
答案1
得分: 1
这是您提供的代码和注释的翻译:
有一些描述不清晰和缺失的细节,所以我会做出一些假设。
-
原则上,你可以绘制你的分割数据
every ::0::12
和every ::13::19
(行索引从零开始),但我假设每个数据文件的行数会变化,并且对于每个文件都不同。 -
你想要绘制 column2 和 column3 与 column1 对比(但也许你想绘制 column2 与 column3 对比)?我假设是前者。
-
你想要使用
with points
绘制。相反,使用with lines
会变得更加复杂,因为你的数据在 column1 从5
回到1
之后没有断点。 -
你没有说明你的 column1 是否只从
1
增加到5
两次,或者可能是N
次?
一般来说,通常你可以调整你的数据,以便绘图命令更容易,或者如果你不能或不想更改原始数据,绘图命令可能会变得有点复杂。
好的,作为进一步检查的起点,请查看以下示例(带有一些完整的测试数据):
脚本:
### 将数据分成子集
reset session
$Data <<EOD
1 11.0 21.0
1 11.3 21.3
1 11.6 21.6
1 11.9 21.9
2 12.0 22.0
2 12.5 22.5
3 13.0 23.0
4 14.0 24.0
4 14.3 24.3
4 14.6 24.6
4 14.9 24.9
5 15.0 25.0
5 15.5 25.5
1 16.0 26.0
2 17.0 27.0
3 18.0 28.0
4 19.0 29.0
4 19.4 29.4
4 19.8 29.8
5 20.0 30.0
EOD
set key out reverse Left noautotitle
myColors = "0xff0000 0x00ff00 0x0000ff 0xff00ff"
myColor(col) = (t0=t1, t1=column(col), t1<t0 ? c=c+1 : 0, int(word(myColors,c)))
myTitles = '"column2, 1st" "column2, 2nd" "column3, 1st" "column3, 2nd"'
plot t1=(c=1,NaN) $Data u 1:2:(myColor(1)) w p pt 7 lc rgb var, \
t1=(c=3,NaN) '' u 1:3:(myColor(1)) w p pt 7 lc rgb var, \
for [i=1:4] keyentry w p pt 7 lc rgb int(word(myColors,i)) ti word(myTitles,i)
### 脚本结束
结果:
补充:
另一个尝试。我不知道你提供的数据是否与实际情况有关。如果你绘制这样的随机数据,为什么要将其分成不同的曲线,即使颜色相同?
无论如何,这里是一种从连续数据中中断曲线的建议(这里还以不同的颜色继续)。"技巧" 是检查 column1 中当前值是否小于前一个值。如果是这样,将线条颜色更改为透明(例如 0xff123456
),否则在三种颜色 RGB 之间循环(或取常数颜色)。透明线条的 "技巧" 缺点是 linespoints 绘图中的第一个数据点将丢失其点(如果需要,可以单独添加)。另一种选择是在 column1 中的每个序列之后引入一个空行(从1到5)。但我假设你不想更改你的 200 MB 数据文件。
请查看以下示例,但很可能我仍然没有完全理解你实际想要的是什么。
脚本:
### 将数据分成多个曲线
reset session
$Data <<EOD
column1 column2 column3
1 2 4
1 3 6
1 5 7
1 9 0
2 5 7
2 8 9
3 9 6
4 4 3
4 2 4
4 6 9
4 0 0
5 7 0
5 6 8
1 5 2
2 3 5
3 6 7
4 8 3
4 2 1
4 2 6
5 8 9
1 1 2 # 为了说明添加了更多的数据
2 3 8
3 1 7
EOD
myColors = "0xff0000 0x00ff00 0x0000ff"
myColor(col) = (t0=t1, t1=column(col), t1<t0 ? (c=c+1, 0xff123456) : int(word(myColors,c%3+1)))
set key noautotitle
plot t1=(c=0,NaN) $
<details>
<summary>英文:</summary>
There are a few details unclear and missing from your description, so I'll make assumptions.
- in principle, you could plot your split data `every ::0::12` and `every ::13::19` (line index is zero-based), but I assume the number of lines will be variable and different for each datafile.
- you want to plot column2 and column3 versus column1 (but maybe you want to plot column2 versus column3)? I assume the former.
- you want to plot `with points`. In contrast, `with lines` will get more complicated because your data doesn't contain breaks after column1 goes from `5` back to `1`.
- you did not specify if your column1 increases from `1` to `5` only twice or maybe `N` times?
Generally, often you can adapt your data, so that the plot commands will be easier or in case you cannot or don't want to change the original data, the plotting commands might get a bit more complicated.
Ok, as a starting point to get any further check the following example (with some completed test data):
**Script:**
break data into subsets
reset session
$Data <<EOD
1 11.0 21.0
1 11.3 21.3
1 11.6 21.6
1 11.9 21.9
2 12.0 22.0
2 12.5 22.5
3 13.0 23.0
4 14.0 24.0
4 14.3 24.3
4 14.6 24.6
4 14.9 24.9
5 15.0 25.0
5 15.5 25.5
1 16.0 26.0
2 17.0 27.0
3 18.0 28.0
4 19.0 29.0
4 19.4 29.4
4 19.8 29.8
5 20.0 30.0
EOD
set key out reverse Left noautotitle
myColors = "0xff0000 0x00ff00 0x0000ff 0xff00ff"
myColor(col) = (t0=t1, t1=column(col), t1<t0 ? c=c+1 : 0, int(word(myColors,c)))
myTitles = '"column2, 1st" "column2, 2nd" "column3, 1st" "column3, 2nd"'
plot t1=(c=1,NaN) $Data u 1:2:(myColor(1)) w p pt 7 lc rgb var,
t1=(c=3,NaN) '' u 1:3:(myColor(1)) w p pt 7 lc rgb var,
for [i=1:4] keyentry w p pt 7 lc rgb int(word(myColors,i)) ti word(myTitles,i)
end of script
**Result:**
[![enter image description here][1]][1]
**Addition:**
Another trial. I don't know if your provided data is anywhere near to something realistic. If you plot such random data, why do you want to separate it into different curves even with the same color?
Anyway, here is a suggestion for interrupting a curve from continuous data (here additionally continuing with a different color).
The "trick" is to check whether the current value in column1 is smaller than the previous value. If this is the case, change the line color to transparent (e.g. `0xff123456`) otherwise loop between the 3 colors RGB (or take constant color).
The transparent line "trick" has the disadvantage that the first data point in a linespoints plot will miss its point (can be added separately if needed).
Another option would be to introduce an empty line after each sequence in column1 (from 1 to 5). But I assume you don't want to change your 200 MB data file.
Check the example below, but it could well be that I still haven't fully understood what you actually want.
**Script:**
break data into several curves
reset session
$Data <<EOD
column1 column2 column3
1 2 4
1 3 6
1 5 7
1 9 0
2 5 7
2 8 9
3 9 6
4 4 3
4 2 4
4 6 9
4 0 0
5 7 0
5 6 8
1 5 2
2 3 5
3 6 7
4 8 3
4 2 1
4 2 6
5 8 9
1 1 2 # some more data added for illustration
2 3 8
3 1 7
EOD
myColors = "0xff0000 0x00ff00 0x0000ff"
myColor(col) = (t0=t1, t1=column(col), t1<t0 ? (c=c+1, 0xff123456) : int(word(myColors,c%3+1)))
set key noautotitle
plot t1=(c=0,NaN) $Data u 2:3:(myColor(1)) w lp pt 7 lc rgb var
end of script
**Result:**
[![enter image description here][2]][2]
[1]: https://i.stack.imgur.com/2HpmG.png
[2]: https://i.stack.imgur.com/NnoIN.png
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论