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
Launch Spyder, the Scientific python IDE bundled with Anaconda.
Set the working directory where plotSlope.py is and import it in the console :
from plotSlope import slopeGrid as slope
And you are good to go.
Load data from file into a data frame :
In [4]:
from plotSlope import slope
# Load some additional lib to load the files
import os
import pandas as pd
In [6]:
# Load data from a csv file and display it
data = pd.read_csv(os.path.join('Data','EU_GDP_2007_2013.csv'),index_col=0,na_values='-')
data/1000
Out[6]:
In [11]:
color = {"France":'b','Germany':'r','Ireland':'chocolate','United Kingdom': 'purple'}
f = slope(data/1000,kind='interval',height= 18,width=20,font_size=15,savename='test.png',color=color,title = u'European GPD until 2010 and forecasts at market prices (billions of Euro) source : EUROSTAT')
In [20]:
f = slope(data/1000,width =30,height= 12,kind='interval',font_size=20,color=color,savename=None,dpi=200)
Other example : Random data
In [15]:
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 [16]:
f = slope(df.T,width =10,height= 8,kind='ordinal',savename=None,dpi=200,color={'10':'red','27':'blue'},marker=None)