我正在尝试获取赛车运动单圈位置表并绘制类似于此的单圈图表 http://www.fia.com/en-GB/sport/championships/f1/2010/bahrain/Pages/lap_chart.aspx。
每行对应一圈,第一圈位于第一行。每行的车号按照通过起跑线/终点线的顺序列出
表格可能如下所示(4 辆车比赛,6 圈:
1 3 2 4
1 3 2 4
1 3 4 2
3 1 4 2
3 1 4 2
3 4 1 2
在上面的例子中,第一圈后的顺序是1、3、2、4,到6圈比赛结束时,3号车获胜,4号车第二,依此类推。
很容易错误地绘制此图,我这样做了:
ListLinePlot[Table[Position[data,x],{x,4}]]
这确实会产生一个圈数图,但它的第一个位置是底部和顶部的第四个位置,我真正需要的是 y 轴运行 4-3-2-1,所以第一个位置在顶部。
如何反转 y 轴,使其从 1(顶部)运行到 n(底部)?
I'm trying to take a table of motorsport lap positions and plot a lap chart similar to this http://www.fia.com/en-GB/sport/championships/f1/2010/bahrain/Pages/lap_chart.aspx.
Each row corresponds to a lap, with the first lap in the first row. The car numbers are listed across each row in the order they pass the start/finish line
The table may look like this (4-car race, 6 laps:
1 3 2 4
1 3 2 4
1 3 4 2
3 1 4 2
3 1 4 2
3 4 1 2
In the above example, the order was 1,3,2,4 after the first lap, and by the end of the 6-lap race, car 3 won, car 4 was in second, and so on.
It's easy to plot this incorrectly, I did this:
ListLinePlot[Table[Position[data,x],{x,4}]]
This does produce a lap chart, but it has 1st position at the bottom and 4th position at the top, and what I really need is the y-axis to run 4-3-2-1 so 1st position is at the top.
How can I reverse the y-axis so it runs from 1(top) to n(bottom)?
发布评论
评论(6)
只需使用象限 4 即可解决屏幕位置问题。
这也适用于DNF! (未完成的驱动程序)。
第一个位置绘制在 y = -1 处,第二个位置绘制在 y = -2 处,依此类推。
请注意
{{lap_, y_} :>; 中的
。y
是如何被-y
替换的。下面的 {lap - 1, -y}}lap
减少了 1,因为我包含了起始位置的数据 (lap=zero)。进行较小的重写,以处理不同数量的驾驶员和圈数,并重新格式化代码以提高易读性。 - Mr.Wizard
这是一辆车(开始于杆位)在完成最后两圈之前就退出了。请注意,3 号车自动前进一位。
Just use Quadrant 4 to settle the position-on-screen problem.
This also works for DNF! (Drivers that did not finish).
First place is plotted at y = -1, second place is plotted at y = -2, etc.
Note how
y
is replaced by-y
in{{lap_, y_} :> {lap - 1, -y}}
below.lap
was decremented by 1 because I included data for the starting position (lap=zero).A minor rewrite, to work with different numbers of drivers and laps, and reformat the code for increased legibility. - Mr.Wizard
Here's the case where car #1 (the one that started in the Pole Position) dropped out before completing the final two laps. Notice that car #3 automatically advanced by one position.
反转位置的顺序,然后重新标记刻度:
Reverse the order of the positions, and then relabel the ticks:
好的,有人提出了
BarChart
和ScalingFunctions
,那么我们开始吧......(但是
ListPlot
解决方案可能更简单。可惜它还不支持ScalingFunctions
。)Ok, someone brought up
BarChart
andScalingFunctions
, so here we go....(but the
ListPlot
solution is probably easier. Too bad it doesn't supportScalingFunctions
yet.)我将放弃这个“聪明”的实现,因为我喜欢它,但大卫的答案更加稳健。
I am going to leave up this "clever" implementation because I like it, but David's answer is far more robust.
现在完全显示 y 轴怎么样:
How about now showing the y-axes at all:
ScalingFunctions
现在似乎可以与ListLinePlot
一起使用,我不知道为什么
AxesOrigin
y 坐标需要为负数。ScalingFunctions
now appears to work withListLinePlot
I have no idea why the
AxesOrigin
y-coordinate needs to be negative.