Line chart of data colored depending on slope for each two x values - colors

is there a way to color data with a variable increase over time depending on the slope?
Let's say for tracking your power usage by looking on your meter from time to time, the data could look like this:
date
kWh
Jan 1
0
Jan 4
20
Jan 12
90
Jan 14
93
I would like to plot a line chart with x = date and y = kWh, but the coloring should be like a heatmap for the slope, so lets say more red for Jan 4 - 12 (average of 8.75 kWh per day), more green for Jan 12 - 14 (1.5 kWh per day) and something yellowish for Jan 1 - 4 (5 kWh average).
Is there a function which spits out the slope for subsets of data, like from each x to the next x value? Is there a way to color a line chart depending on this slope value for each x value?
Thanks a lot!
Something like this (here its colored by altitude):
pic

Related

Change cell color based on percent attainment of goal

I have the following data
Calls
Week 1 Goal 75
M 10
T 15
W 9
T 20
F 22
Week 4 Total 76
Attainment % 101%
I'd like to change the color of the daily number based on whether or not the total is consistent with attaining the goal in the "Week 1 Goal" row. That is, for Wednesday, if the sum of the values for M, T, W >= 3*(75/5), I'd like the value for W to be green, otherwise red. For Thursday, if the values for M, T, W, Th >= 4*(75/5), and so on.
Thanks!

Comparing data frames with a level of error

I have two dataframes as
df_schematic
layer x y
0 18 -10850.0 -6550.0
1 18 -10850.0 -5750.0
2 18 -10950.0 -5850.0
3 18 -10950.0 -5450.0
4 31 -10850.0 -5350.0
5 14 -10850.0 -4950.0
6 17 2945.5 6550.0
2278 rows × 3 columns
df_report
layer x y
0 18 9161.19 -3106.42
1 18 9141.51 -3185.38
2 18 9023.40 -3185.38
3 18 9003.71 -3106.42
4 18 8800.20 -2840.65
5 17 2945.8 6549.6
2216 rows × 3 columns
i am trying to compare df_schematic with the report and find out any missing or irregular values among the report. The main problem is the level of tolerance we can have for a coordinate.
For example:
17 2945.5 6550.0
and
17 2945.8 6549.6
are clearly not equal but they should be passed as a correct entry as the error level is +/-0.5.
Is there any way to find out the missing values and while keeping the tolerance in mind.
Make some experiments with np.isclose.
I mean the following scenario:
Write a function, say isClose, comparing one pair of coordinates (x1, y1) with
another pair (x2, y2), from 2 source rows, something like
np.isclose(x1, x2, atol=0.5) & np.isclose(y1, y2, atol=0.5).
Taking a row from df_schematic as a "base point":
find in df_report all rows with exactly equal value of layer,
for each such row check isClose for x and y coordinates from both rows,
until you find one where this function returns True.
Repeat this procedure for each row from df_schematic.

Difference between consecutive maxima and minima in a .csv dataset

I have a dataset which represents tracking data of a mouse's paw moving up and down in the y-axis as it reaches up for and pulls down on a piece of string.
The output of the data is a list of y-coordinates corresponding to a fraction of a second. For example:
1 333.9929833
2 345.4504726
3 355.7046572
4 367.6136684
5 379.7906121
6 390.5470788
7 397.9017118
8 403.677123
9 412.1550843
10 416.516814
11 419.8205706
12 423.7994881
13 429.4874275
14 419.2652898
15 360.1626136
16 298.8212249
17 264.3647809
18 265.0078862
19 268.1828407
20 283.101321
21 294.8219163
22 308.4875135
In this series, there is a max value of 429... and a minimum of 264... - however, as you can see from an example image:
(excuse the gaps), there are multiple consecutive wave-like maxima and minima.
The goal is to find the difference between each maxima and consecutive minima, and each minima and consecutive maxima (i.e. max1-min1, min2-max1, max2-min2...). Ideally, this would also provide the timepoints of each max and min (e.g. 13 and 17 for the provided dataset) - there is a column with integer labels (1, 2, 3...) corresponding to each coordinate.
Thanks for your help!

Microsoft Excel Pie Chart bug

Pie chart percentage not calculated correctly by excel. In the picture you can see that the c and d values are exactly the same, but for some reason "c" has a higher percentage denoted to it and I can't figure out why.
The values are a-21; b-5; c-11; d-11; e-3; f-5; g-1; h-39. On the pie chart the percentage received is a-22%; b-5%; c-12%; d-11%; e-3%; f-5%; g-1%; h-41%
While not the ideal solution, if you right click on one of the labels and press the Format Data Labels option, you can change the Number display type to percentage, this will increase the number of decimal places in the percentage shown but give you the accurate result asked for.
The problem is caused by your actual percentages being:
Name Val %
a 21 21.875
b 5 5.208333333
c 11 11.45833333
d 11 11.45833333
e 3 3.125
f 5 5.208333333
g 1 1.041666667
h 39 40.625
As you can see these numbers can't be exactly represented as a (whole number) percentage, the compensations have to be made somewhere. It just so happened that the compensations were made on numbers that should be the same.
Another possible option would be to round your percentage results:
Name Val % Rounded %
a 21 21.875 22
b 5 5.208333333 5
c 11 11.45833333 11
d 11 11.45833333 11
e 3 3.125 3
f 5 5.208333333 5
g 1 1.041666667 1
h 39 40.625 41
The sum of these values is now 99 instead of 96 as in your original, which results in a better graph:
You can do this using the formula =ROUND(num,0) for each of your calculated percentages.

Regression Line in different Excel Charts

I have the following Excel spreadsheet:
A B C D E F
1 X-Values Y-Values
2 Year Revenue X-Ø Y-Ø (X-Ø) x (Y-Ø) (X-Ø)^2
3 2012 10 -1.5 -55 82.5 2.25
4 2013 50 -0.5 -15 7.5 0.25
5 2014 80 0.5 15 7.5 0.25
6 2015 120 1.5 55 82.5 2.25
7
8 2013.5 65 180 5.0
9
10 Slope: 36.00 (=180/5.0)
11 Y-Intercept: -72,421 (=65 - 36 x 2013.5)
12
In Area A3:B6 you can see the Year and the corresponding Revenue. Now I want to make a simple trend analysis for it. Therefore, I manually calculated the Regression Line in Area C3:F6 and in Cell B10 (Slope) and Cell B11 (Y-Intercept) which leads to the following formula:
y = 36X - 72,421
Now I want to do the same thing with an Excel chart. First I put the data in Area A3:B6 in a Scatter Chart and I got the following formula for the Regression Line: (Matches exactly the manual calculated formula)
Scatter Chart:
When I put the same data into a Line Chart I get a different formula for the Regression Line:
Line Chart:
Why does the formula from the Line Chart differ from the Scatter Chart and how is it calculated?
On the scatter chart the value of x is the value for the year, so the values are 2012, 2013, 2014, 2015.
On the line chart the values of x are 1, 2, 3, 4, with the year being the label for the x value.

Resources