使用 ListLinePlot 的赛车圈速图 [英] Motorsport Lap Chart using ListLinePlot
问题描述
我正在尝试获取赛车圈位置表并绘制类似于此的圈数图表 http://www.fia.com/en-GB/sport/championships/f1/2010/bahrain/Pages/lap_chart.aspx.
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.
每一行对应一圈,第一圈在第一行.车号按照它们通过起点/终点线的顺序在每一行中列出表格可能看起来像这样(4 车比赛,6 圈:
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
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号车第二,依此类推.
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}]]
这确实产生了一个圈数图,但它在底部有第 1 个位置,在顶部有第 4 个位置,我真正需要的是 y 轴来运行 4-3-2-1,所以第一个位置是顶.
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.
如何反转 y 轴,使其从 1(顶部)运行到 n(底部)?
How can I reverse the y-axis so it runs from 1(top) to n(bottom)?
推荐答案
只需使用象限 4 来解决屏幕上的位置问题.
Just use Quadrant 4 to settle the position-on-screen problem.
这也适用于 DNF!(未完成的驱动程序).
This also works for DNF! (Drivers that did not finish).
第一名绘制在 y = -1 处,第二名绘制在 y = -2 处,依此类推.注意 y
如何在 {{lap_, y_} 中被
下面.-y
替换:>{lap - 1, -y}}
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
减 1,因为我包含了起始位置的数据(lap=0).
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
data =
{{1, 3, 2, 4},
{1, 3, 2, 4},
{1, 3, 4, 2},
{3, 1, 4, 2},
{3, 1, 4, 2},
{3, 4, 1, 2}};
{p, n} = {Max@data, Length@data};
ticks = {#, #} &@Array[{-#, #} &, p];
ticks[[All, 1, 2]] = {"Pole", "Winner"};
PrependTo[data, Range@p]; (* add starting position *)
ListLinePlot[
Replace[
Array[data~Position~# &, p],
{lap_, y_} :> {lap - 1, -y},
{2}
],
Frame -> True,
FrameLabel ->
{"Laps Completed",
"Starting Positions",
"Laps Completed",
"Final Positions"},
GridLines -> {Range[0, n + 1], None},
FrameTicks -> {ticks, {All, All}},
PlotRange -> {Automatic, {-.7, -.3 - p}},
PlotStyle -> Thickness[.01]
]
在这种情况下,1 号车(从杆位发车的那辆车)在完成最后两圈之前退出.请注意,3 号车自动前进了一个位置.
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.
这篇关于使用 ListLinePlot 的赛车圈速图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!