How can I create stacked line graph with matplotlib?

Matplotlib does not have an "out-of-the-box" function that combines both the data processing and rendering steps, but it's easy to roll your own from components supplied by Matplotlib and NumPy The code below "stack" the data, then draws the plot (As an aside: I was trying to find the generally accepted name for this type of plot. As you can see below, Matplotlib is quite good at drawing them, but it doesn't have a name for them (nor obviously a separate convenience function). One of R's plotting libraries refers to this format as an area plot In addition, these plots look like 'density plots' but they're not--the convention seems to be that multiple density plots (more than one series plotted on the same axis) refer to overlaid rather than stacked data (multiple histogram series are stacked by convention though) import numpy as NP from matplotlib import pyplot as PLT # just create some random data fnx = lambda : NP.random.

Randint(3, 10, 10) y = NP. Row_stack((fnx(), fnx(), fnx())) # this call to 'cumsum' (cumulative sum), passing in your y data, # is necessary to avoid having to manually order the datasets x = NP. Arange(10) y_stack = NP.

Cumsum(y, axis=0) # a 3x10 array fig = PLT.figure() ax1 = fig. Add_subplot(111) ax1. Fill_between(x, 0, y_stack0,:, fc="#CC6666", alpha=.7) ax1.

Fill_between(x, y_stack0,:, y_stack1,:, fc="#1DACD6", alpha=.7) ax1. Fill_between(x, y_stack1,:, y_stack2,:, fc="#6E5160") PLT.show().

Matplotlib does not have an "out-of-the-box" function that combines both the data processing and rendering steps, but it's easy to roll your own from components supplied by Matplotlib and NumPy. The code below "stack" the data, then draws the plot. (As an aside: I was trying to find the generally accepted name for this type of plot.As you can see below, Matplotlib is quite good at drawing them, but it doesn't have a name for them (nor obviously a separate convenience function).

One of R's plotting libraries refers to this format as an area plot. In addition, these plots look like 'density plots' but they're not--the convention seems to be that multiple density plots (more than one series plotted on the same axis) refer to overlaid rather than stacked data (multiple histogram series are stacked by convention though). Import numpy as NP from matplotlib import pyplot as PLT # just create some random data fnx = lambda : NP.random.

Randint(3, 10, 10) y = NP. Row_stack((fnx(), fnx(), fnx())) # this call to 'cumsum' (cumulative sum), passing in your y data, # is necessary to avoid having to manually order the datasets x = NP. Arange(10) y_stack = NP.

Cumsum(y, axis=0) # a 3x10 array fig = PLT.figure() ax1 = fig. Add_subplot(111) ax1. Fill_between(x, 0, y_stack0,:, fc="#CC6666", alpha=.7) ax1.

Fill_between(x, y_stack0,:, y_stack1,:, fc="#1DACD6", alpha=.7) ax1. Fill_between(x, y_stack1,:, y_stack2,:, fc="#6E5160") PLT.show().

– honk Feb 9 '10 at 9:25 If you want to create a legend for this kind of graph, I think you need to use proxy "Artists" matplotlib.sourceforge. Net/users/… – Andrew B. Dec 9 '10 at 20:35.

A slightly less hackish way would be to use a line graph in the first place and matplotlib.pyplot. Fill_between. To emulate the stacking you have to shift the points up yourself.

X = np. Arange(0,4) y1 = np. Array(1,2,4,3) y2 = np.

Array(5,2,1,3) # y2 should go on top, so shift them up y2s = y1+y2 plot(x,y1) plot(x,y2s) fill_between(x,y1,0,color='blue') fill_between(x,y1,y2s,color='red').

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions