I would like to show how typical days of energy load (found through clustering of a years worth of data) are spread throughout a year in a single graph with a color for each 'typical day' (or cluster).
What I have so far
Here is the data in pastebin.
I divided the daily load curves (365 * 24 measurements) into clusters:
loadclust = FindClusters[load, num]
Each list within a cluster represents a daily load curve within a year, but each cluster doesn't contain the same amount of days.
To these daily loads (lists) I then joined a list which corresponds to the hours in a year (i.e. 1 to 24 for first day, 25 to 48 for second, etc...). I did this by finding the position of each daily list in the original ordered list, since I wanted to keep the different clusters in order.
clustyearh = Flatten[Table[
Table[
Join[
Range[(Flatten[Position[load, loadclust[[j, i]], 1 ]] - 1)*24 +
1, Flatten[Position[load, loadclust[[j, i]], 1 ]]*24]
, {loadclust[[j, i]]}
], {i, Length [loadclust[[j]]]}
], {j, Length[loadclust]}
], 1];
Then I made pairs of the hour in the year and the load at that hour, while still maintaining the order of the clusters (so there are fours lists containing the paired coordinates for each cluster).
pairs = Table[
Transpose[
Join[{Flatten[
Transpose[
clustyearh[[;; Length[loadclust[[i]]]]]][[1]]]}, {Flatten[
Transpose[clustyearh[[;; Length[loadclust[[i]]]]]][[2]]]}]]
, {i, 4}];
The result is a list of four lists of pairs {{{1, 1368},... {24, 1428}, {121, 1321}, ...} {clust2} {..}{..}}
Plotting
This is where I am having problems.
First, when I used Listplot
for pairs
, it doesn't display all the points (I notice that it's the blue and red clusters especially missing).
Second, when I include Joined -> True
it joins the consecutive days in each cluster, but not in the year. If cluster one has days 1, 2, 5, 59 for example it will join those days.
Question
Is there a way to color each cluster within a line graph for the whole year?
As an addition, I would love to be able to apply Manipulate
to scroll through the year within a week or 2 week window.
Using Simon Wood's solution :
Create a list of indexes for the clustered days.
loadclust = FindClusters[load -> Range[365], 4];
Then make pairs of data to give as coordinates to a ListPlot
, while adding data for a 25th hour for each day (i.e. the first hour of the next day) so the plot will be joined at all points:
With[{load2 = Append[load, {{0}}]},
pairs = Map[
Sequence @@
Thread[{24 (# - 1) + Range[25],
Append[load2[[#]], load2[[# + 1, 1]]]}] &, loadclust, {2}]];
Create a manipulate graph to view the graph inside of a window (I have added the colors I originally used for each cluster).
Manipulate[
ListLinePlot[pairs, Frame -> True, Axes -> False,
PlotRange -> {{n, n + win - 1}, All},
PlotStyle -> {Blue, Orange, Red, Green}] /.
Line[pts_] :> Line[Split[pts, #2[[1]] - #1[[1]] == 1 &]], {{n, 1,
"First Hour"}, 1, 24*365 - win, 1}, {{win, 168, "Window Length"},2, 336, 1}]
http://pastebin.com
. I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2)Read the FAQs
! 3) When you see good Q&A, vote them up byclicking the gray triangles
, because the credibility of the system is based on the reputation. Remember to accept the answer, if any, that solves your problem,by clicking the checkmark sign
` $\endgroup$