So here is my entry for the slope Graph contest. (You can find the initial bounty description here )
This script is written in Python and relies on Numpy, Pandas and Matplotlib.
The easiest way to have a clean and robust install is to download one the great Scientific Python distribution, nameley :
Everything you'll need is included. I personally use Anaconda from the guys at Continuum Analytics. All of them should work on Linux, Windows and Mac.
Go grab the sources at https://github.com/pascal-schetelat/Slope
python setup.py install
Then you are good to go. Import it in a Python interpreter (for instance Spyder, the Scientific python IDE bundled with Anaconda, or a jupyter notebook):
from plotSlope import slope
Import :
In [4]:
from plotSlope import slope
Load data from file into a data frame :
In [7]:
data = pd.read_csv(os.path.join('data','EU_GDP_2007_2013.csv'),index_col=0,na_values='-')
(data/1000).head()
Out[7]:
Plot it :
In [6]:
f = slope(data/1000,kind='interval',height= 12,width=20,font_size=12,dpi=150,savename='EU_interval.png',title = u'title')
In [9]:
color = {"France":'b','Germany':'r','Ireland':'chocolate','United Kingdom': 'purple'}
f = slope(data/1000, title = u'European GPD until 2010 and forecasts at market prices (billions of Euro) source : EUROSTAT',
kind='interval',height= 12,width=22,font_size=15,
savename='test.png',color=color,dpi=200)
In [10]:
f = slope(data/1000, title = u'European GPD until 2010 and forecasts at market prices (billions of Euro) source : EUROSTAT',
kind='interval',height= 12,width=30,font_size=20,
savename=None,color=color)
In [11]:
df = pd.DataFrame( np.random.normal(loc=np.ones(shape=[20,30])*np.arange(30)))
df.rename(columns = lambda el : str(el),index =lambda el : str(el),inplace=True)
In [12]:
f = slope(df.T,width =10,height= 8,kind='ordinal',savename=None,dpi=200,color={'10':'red','27':'blue'},marker=None)