This is my first time posting so I apologize if asking a new question based on a pre-exisitng one is bad form.
I am trying to create a "lap chart" similar to the one presented here:
Motorsport Lap Chart using ListLinePlot
My need has a bit of a twist. I am charting the lap positions for a different sport and my data is structured differently. The data is listed by team and the position the team was in at the completion of each lap. For example, here is a sample of the data:
BRA = {03, 01, 01, 01};
CAN = {14, 14, 06, 10};
CRO = {10, 08, 11, 12};
DEN = {05, 05, 04, 11};
FRA = {13, 11, 14, 13};
GBR = {04, 02, 02, 02};
GER = {15, 15, 12, 09};
GRE = {16, 16, 16, 16};
IRL = {01, 03, 08, 06};
NOR = {02, 04, 09, 05};
NZL = {06, 06, 05, 08};
POL = {08, 07, 03, 03};
POR = {11, 13, 15, 15};
SUI = {07, 09, 10, 07};
SWE = {09, 10, 07, 04};
USA = {12, 12, 13, 14};
In this example Brazil was in third place at the end of the first lap and then moved into first by the end of the second, holding the place for the third lap and then to the finish.
I have created the chart I need by manually retyping the data in a format to fit the code posted in the earlier example, but there has to be a more efficient way. Any suggestions are appreciated.
One other question... currently the positions at the end of a given lap are spaced evenly apart, however in the real race first place was 20 seconds ahead of second who was perhaps 10 seconds ahead of third. Is there a way to plot each position to reflect the relative time ahead of the next competitor?
Here is my current working code:
data = {{09, 10, 01, 06, 04, 11, 14, 12, 15, 03, 13, 16, 05, 02, 07, 08},
{01, 06, 09, 10, 04, 11, 12, 03, 14, 15, 05, 16, 13, 02, 07, 08},
{01, 06, 12, 04, 11, 02, 15, 09, 10, 14, 03, 07, 16, 05, 13, 08},
{01, 06, 12, 15, 10, 09, 14, 11, 07, 02, 04, 03, 05, 16, 13, 08}};
{p, n} = {Max#data, Length#data};
ListLinePlot[
Replace[Array[data~Position~# &,
p], {lap_, y_} :> {lap - 1, -y}, {2}],
Frame -> True,
FrameLabel -> {"Rounding", "Position", "Rounding",
"Final Positions"}, GridLines -> {Range[0, n + 1], None},
FrameTicks -> {
{{{-1, "IRL"}, {-2, "NOR"}, {-3, "BRA"}, {-4, "GBR"}, {-5,
"DEN"}, {-6, "NZL"}, {-7, "SUI"}, {-8, "POL"}, {-9,
"SWE"}, {-10, "CRO"}, {-11, "POR"}, {-12, "USA"}, {-13,
"FRA"}, {-14, "CAN"}, {-15, "GER"}, {-16, "GRE"}},
{{-1, "1 BRA"}, {-2, "2 GBR"}, {-3, "3 POL"}, {-4, "4 SWE"}, {-5,
"5 NOR"}, {-6, "6 IRL"}, {-7, "7 SUI"}, {-8, "8 NZL"}, {-9,
"9 GER"}, {-10, "10 CAN"}, {-11, "11 DEN"}, {-12,
"12 CRO"}, {-13, "13 FRA"}, {-14, "14 USA"}, {-15,
"15 POR"}, {-16, "16 GRE"}}},
{{{0, "W1"}, {1, "L1"}, {2, "W2"}, {3, "F"}},
{{0, "W1"}, {1, "L1"}, {2, "W2"}, {3, "F"}}}},
PlotRange -> {Automatic, {-.7, -.3 - p}},
PlotStyle -> Thickness[.003]]
Here you have how to reformat your data with minimal manual effort.
tot = {
BRA = {03, 01, 01, 01}, CAN = {14, 14, 06, 10}, CRO = {10, 08, 11, 12},
DEN = {05, 05, 04, 11}, FRA = {13, 11, 14, 13}, GBR = {04, 02, 02, 02},
GER = {15, 15, 12, 09}, GRE = {16, 16, 16, 16}, IRL = {01, 03, 08, 06},
NOR = {02, 04, 09, 05}, NZL = {06, 06, 05, 08}, POL = {08, 07, 03, 03},
POR = {11, 13, 15, 15}, SUI = {07, 09, 10, 07}, SWE = {09, 10, 07, 04},
USA = {12, 12, 13, 14}}
then do
data = Ordering /# Transpose#tot
and using #DavidCarraher's answer in the question you mentioned.
Edit
If you have the timings for each team (for each lap), here is a skeleton for plotting a time scaled plot:
lapTimes = RandomReal[{0, 1}, {10, 5}];(*ten teams,five laps*)
ListLinePlot[Accumulate /# lapTimes, PlotRange -> {{1, 5}, All}]
The lower line at the end is the winner (less time consumed)
Related
I have a script that can post a text or an image to the VK.com over API. But I can't find a way to create a poaster:
There is no information about posters at the official documentation page.
You have to add the parameter poster_bkg_id = {background_number_for_poster}. This parameter is not described in the documentation (thanks to the author https://github.com/VBIralo/vk-posters).
Backgrounds (poster_bkg_id)
Gradients
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Artwork
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32
Emoji Patterns
21, 22, 23, 24, 25, 26, 27, 28, 29, 30
If you type the following string into a text file encoded with utf8(without bom) and open it with notepad.exe,you will get some weired characters on screen. But notepad can actually decode this string well without the last 'a'. Very strange behavior. I am using Windows 10 1809.
[19, 16, 12, 14, 15, 15, 12, 17, 18, 15, 14, 15, 19, 13, 20, 18, 16, 19, 14, 16, 20, 16, 18, 12, 13, 14, 15, 20, 19, 17, 14, 17, 18, 16, 13, 12, 17, 14, 16, 13, 13, 12, 15, 20, 19, 15, 19, 13, 18, 19, 17, 14, 17, 18, 12, 15, 18, 12, 19, 15, 12, 19, 18, 12, 17, 20, 14, 16, 17, 18, 15, 12, 13, 19, 18, 17, 18, 14, 19, 18, 16, 15, 18, 17, 15, 15, 19, 16, 15, 14, 19, 13, 19, 15, 17, 16, 12, 12, 18, 12, 14, 12, 16, 19, 12, 19, 12, 17, 19, 20, 19, 17, 19, 20, 16, 19, 16, 19, 16, 12, 12, 18, 19, 17, 18, 16, 12, 17, 13, 18, 20, 19, 18, 20, 14, 16, 13, 12, 12, 14, 13, 19, 17, 20, 18, 15, 12, 15, 20, 14, 16, 15, 16, 19, 20, 20, 12, 17, 13, 20, 16, 20, 13a
I wonder if this is a windows bug or there is something I can do to solve this.
Did more research; figured it out.
Seems like a variation of the classic case of "Bush hid the facts".
https://en.wikipedia.org/wiki/Bush_hid_the_facts
It looks like Notepad has a different character encoding default for saving a file than it does for opening a file. Yes, this does seem like a bug.
But there is an actual explanation for what is occurring:
Notepad checks for a BOM byte sequence. If it does not find one, it has 2 options: the encoding is either UTF-16 Little Endian (without BOM) or plain ASCII. It checks for UTF-16 LE first using a function called IsTextUnicode.
IsTextUnicode runs a series of tests to guess whether the given text is Unicode or not. One of these tests is IS_TEXT_UNICODE_STATISTICS, which uses statistical analysis. If the test is true, then the given text is probably Unicode, but absolute certainty is not guaranteed.
https://learn.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-istextunicode
If IsTextUnicode returns true, Notepad encodes the file with UTF-16 LE, producing the strange output you saw.
We can confirm this with this character ㄠ. Its corresponding ASCII characters are ' 1' (space one); the corresponding hex values for those ASCII characters are 0x20 for space and 0x31 for one. Since the byte-ordering is Little Endian, the order for the Unicode code point would be '1 ', or U+3120, which you can confirm if you look up that code point.
https://unicode-table.com/en/3120/
If you want to solve the issue, you need to break the pattern which helps IsTextUnicode determine if the given text is Unicode. You can insert a newline before the text to break the pattern.
Hope that helped!
I have been using a kendochart as in the example: http://jsfiddle.net/ericklanford/6dr0k59v/2/
the categoryAxis is deffined as:
categoryAxis: {
categories: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31],
majorGridLines: {
visible: false
},
},
If you note, it is difficult to see the labels under the categoryAxis.
There is any possibility to do something like this:
What you are proposing with your image is not available out of the box (but it is possible through some hacks). Officially you have two options - rotate the labels or skip every other label:
Skip every other label
To do that you need to specify a step value when you configure the labels, like this:
// ...
categoryAxis: {
categories: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31],
labels: {
step: 2
},
majorGridLines: {
visible: false
},
}
// ...
Rotate the labels
This will prevent them from overlapping because they will be sideways. That way they are easier to read, while you are not missing every other label. You need to set the rotation value to -90:
// ...
categoryAxis: {
categories: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31],
labels: {
rotation: -90
},
majorGridLines: {
visible: false
},
}
// ...
... and the hacky way
This is not officially supported and it requires some manipulation of the rendered svg image. We need to slightly change the color of the axis first, so that we can find the elements by color:
// ...
categoryAxis: {
categories: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31],
color: "#000001",
majorGridLines: {
visible: false
},
}
// ...
And then we will run a script that will find all the labels and increase the "y" position of every other label by 8 pixels:
$(document).ready(createChart);
var axisLabels = $("#chart").find("text[fill='#000001']");
for(i = 0; i < axisLabels.length; i += 2){
$(axisLabels[i]).attr("y",parseInt($(axisLabels[i]).attr("y")) + 8);
}
And here's the fiddle: http://jsfiddle.net/4Lsownbp/
I am trying to find all the possible differences between the elements of one list.
For example:
x=[1,4,10,17,20,35].
I would like to have as an answer an array:
y=[3, 9, 16, 19, 34, 3, 6, 13, 16, 31, 9, 6, 7, 10, 25, 16, 13, 10, 3, 18, 19, 16, 10, 3, 15, 34, 31, 25, 18, 15]
corresponding to
[1-4, 1-10, 1-17, 1-20, 1-35, 4-1, 4-10, 4-17, ....]
I have tried to do that with diff, but I only get the difference of two consecutive numbers. and I do not really know how to compute it in a loop.
Can you please help?
A Python 1-liner:
>>> [abs(a - b) for i,a in enumerate(x) for j,b in enumerate(x) if i != j]
[3, 9, 16, 19, 34, 3, 6, 13, 16, 31, 9, 6, 7, 10, 25, 16, 13, 7, 3, 18, 19, 16, 10, 3, 15, 34, 31, 25, 18, 15]
A solution written in python
elements = [1,4,10,17,20,35]
differences = []
for i , element in enumerate(elements):
for j, element2 in enumerate(elements):
if i != j:
differences.append( abs(element - element2) )
Writing in Java, it is as simple as this:
List<Integer> diff = new ArrayList<Integer>();
for(int i=0; i<list.size(); i++) {
for(int j=0; j<list.size(); j++) {
if(i != j)
diff.add(Math.abs(list.get(i) - list.get(j)));
}
}
I have hours in an array 1 - 24 as integers just like that. I want to know how to format the x axis for that those values are displayed as times 12:00 am - 12:00 pm. I cant seem to figure out how to do it.
Here's one way you could do it.
var hours = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24
];
var timeformat = d3.time.format('%I:%M%p');
var now = new Date()
now.setHours(hours[15]);
now.setMinutes(0);
var time = timeformat(now); // 04:00PM
Working Fiddle