Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have 23 variables (energy production units) which take values for each hour of the day (energy dispatch table). Here is a PasteBin example of data. I am trying to represent the distribution of the total energy production for each hour. So far I have managed a pretty decent plot using :

accunits = Table[Accumulate[Transpose[allunits][[k]]], {k, Range[24]}];
ListLinePlot[Transpose[accunits], PlotRange -> All, AxesOrigin -> {1, 0}, ImageSize -> 500, Filling -> colors, PlotStyle -> Opacity[0]]

I still don't fully understand the proper use of FillingStyle with ColorData, so I created a list :

colors = Join[
 Table[i -> {{i + 1}, Yellow}, {i, 1, 3}],
 Table[i -> {{i + 1}, Orange}, {i, 4, 8}],
 Table[i -> {{i + 1}, Red}, {i, 9, 15}],
 Table[i -> {{i + 1}, Brown}, {i, 16, 20}],
 {21 -> {{22}, Blue}},
 {22 -> {{23}, Green}}];

Note the two last units are hydro and renewables, so the color scheme is different, while the 21 other units are thermal, so I tried to recreate a simplified TemperatureMap. This gives me the following image

Dispatch

My question(s) is:
How can I refine the plot so that the lines between colored regions don't appear so aliased and so that the space between the x-axis and the first unit is also colored? Also, how can I apply a temperature color scheme independent of the number of thermal units (the last two units are always hydro/blue and renewables/green)?

EDIT 1 : I found a solution for the coloring of the first unit, by adding a list of zeros as a first "unit" (I had to change the colors list to take into account this extra first "unit"):

accunits2 = Table[Accumulate[Transpose[Prepend[allunits2[[i, j]], Table[0, {p, Range[24]}]]][[k]]], {k,Range[24]}]

Cheers, E

share|improve this question
    
@kugler PlotRangePadding->0 doesn't seem to work for the white space. A workaround I found is to add a list of 0s as a "first unit". accunits2 = Table[Accumulate[Transpose[Prepend[allunits2[[i, j]], Table[0, {p, Range[24]}]]][[k]]], {k,Range[nh]}]; edit : The comment I'm referring to was removed. –  Emy Feb 7 '13 at 13:59
1  
you are right (that's why the comment was removed :). Another workaround is to use colors = Join[colors, {1 -> {Axis, Yellow}}]. –  kguler Feb 7 '13 at 14:10
    
@Emy Is allunits2 the same as allunits in your code? What is nh? –  halirutan Feb 7 '13 at 14:11
    
@halirutan Yeah, sorry. It's because I have 7x10 runs for the dispatch (different prices and renewable size. I'll edit that out though). nh is just the number of periods (hours) I will change it in my original question as well. –  Emy Feb 7 '13 at 14:16

2 Answers 2

up vote 4 down vote accepted

To refine your plot so that the lines between colored regions don't appear so choppy you can resample your data by using Interpolation.

a = Interpolation /@ Transpose[accunits];
accunitsNew = Table[a[[i]][x], {x, 1, 24, .1}, {i, Length[a]}];
ListLinePlot[Transpose[accunitsNew], PlotRange -> All, 
    AxesOrigin -> {1, 0}, ImageSize -> 500, Filling -> colors, PlotStyle -> Opacity[0]]

enter image description here

To apply a temperature color scheme independent of the number of thermal units you can try this approach:

colors = Join[
    Table[i -> {{i + 1}, 
       ColorData["TemperatureMap"][(i - 1)/(# - 1)]}, {i, 
      1, #}], {# + 1 -> {{# + 2}, Blue}}, {# + 2 -> {{# + 3}, 
       Green}}] &;
linecolors = 
  Join[{White}, 
    Table[ColorData["TemperatureMap"][(i - 1)/(# - 1)], {i, 
      1, #}], {Blue, Green}] &;
ListLinePlot[Transpose[accunitsNew], PlotRange -> All, 
 AxesOrigin -> {1, 0}, ImageSize -> 500, 
 Filling -> colors[Length[Transpose[accunitsNew]] - 3], 
 PlotStyle -> linecolors[Length[Transpose[accunitsNew]] - 3]]

The number of colors will be always generated for the correct number of thermal units and the colors will always span the whole range of the temperature color scheme. I've also added the correct colors for the PlotStyle.

enter image description here

share|improve this answer
    
That looks great, but I think I misphrased my question. I wanted the lines to be less aliased. I think it stems from the fact that it is drawing lines with Opacity[0]. –  Emy Feb 7 '13 at 14:28
    
Very nice VLC, thanks. That explains a lot on ColorData. I changed the color scheme to SolarColors as I really only wanted the "hotter" part of TemperatureMap. As I told kguler below, I think I will try and adapt your code with his boundaries idea and plot only lines when there is a change of color. What does SE etiquette dictate here? Should I wait for a fuller answer, or just go ahead and accept yours since it is most complete? Cheers, Emy –  Emy Feb 8 '13 at 11:43
    
@Emy You're welcome. I think you can wait another day to see if any new answer pops up. The SE etiquette just says that it is up to you which answer to pick. –  VLC Feb 8 '13 at 12:01
    
So I came back from a small trip and no better answers, so I will accept yours. I'll also update my question to include my modified code. Thanks again. –  Emy Feb 13 '13 at 19:17

Plotting the 6 series corresponding to region boundaries (rather than 23 series) and replacing Opacity[0.] in PlotStyle by the filling color:

 boundaries = {3, 8, 15, 20, 22, 23};
 pltstyles = {Yellow, Orange, Red, Brown, Blue, Green};
 ListLinePlot[Accumulate[allunits2][[boundaries]],
 PlotStyle -> pltstyles,
 Filling -> ({# -> {{# - 1}, pltstyles[[#]]}} & /@ Range[6, 1, -1] /.    
  Rule[1, {{0}, col_}] :> Rule[1, {Axis, col}]),
 PlotRange -> All, AxesOrigin -> {1, 0},   ImageSize -> 600] 

enter image description here

or

 Show[ListLinePlot[Accumulate[allunits2][[boundaries[[#]]]],
 PlotStyle -> pltstyles[[#]],
 Filling -> Axis, FillingStyle -> pltstyles[[#]],
 PlotRange -> All, AxesOrigin -> {1, 0},
 ImageSize -> 600] & /@ Reverse[Range[6]]]
share|improve this answer
    
Thanks for that. I wanted as many colors as units though. I will try and adapt your response to VLC's response, as he got the colors part (almost) right, but yours does get rid of the aliasing. Another problem with the graph that your answer might solve is that there are several units which don't turn on until later, or not at all, but are still being plotted. I will have to work on that too. Thanks for the help. Emy –  Emy Feb 8 '13 at 11:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.