Cufflinks v0.6

In [1]:
import cufflinks as cf
import pandas as pd
In [2]:
%reload_ext autoreload
%autoreload 2
In [3]:
cf.set_config_file(world_readable=True,offline=False)

Pie Charts

datagen can now generate a DataFrame with the structured required for a pie charts

In [5]:
pie=cf.datagen.pie()
pie.head()
Out[5]:
labels values
0 a 24
1 b 51
2 c 71
3 d 59
4 e 91

iplot now accepts the paramter kind=pie to generate a pie chart
labels indicates the column that contains the category labels, and values indicates the column that contain the values to be charted

In [6]:
pie.iplot(kind='pie',labels='labels',values='values')
Out[6]:

Extra parameters can also be passed
sort : If True it sorts the labels by value
pull : Pulls the slices from the centre
hole : Sets the size of the inner hole
textposition Sets the position of the legends for each slice ('outside'|'inside')
textinfo : Sets the information to be displayed on the legends

In [7]:
pie.iplot(kind='pie',labels='labels',values='values',pull=.2,hole=.2,
         colorscale='blues',textposition='outside',textinfo='value+percent')
Out[7]:

Open, High, Low, Close Data Generation

datagen now includes a method ohlc to generate Open, High, Low, Close data

In [8]:
ohlc=cf.datagen.ohlc()
ohlc.head()
Out[8]:
open high low close
2015-01-01 00:00:00+00:00 100.000000 132.970339 100.000000 122.653923
2015-01-02 00:00:00+00:00 122.784443 134.059851 119.796955 128.633687
2015-01-03 00:00:00+00:00 129.674902 141.297684 117.874735 133.193830
2015-01-04 00:00:00+00:00 133.339331 133.610792 115.809525 117.821833
2015-01-05 00:00:00+00:00 116.371798 146.456216 112.284398 142.638943
In [9]:
ohlc.iplot()
Out[9]:

Candle and Bar Charts

Of course OHLC can always be better appreciated with candle and bar (OHLC) charts.

You can now achieve this with kind=candle and kind=ohlc in iplot.

In [10]:
ohlc.iplot(kind='ohlc')
Out[10]:
In [11]:
ohlc.head().iplot(kind='candle',theme='ggplot',up_color='blue',down_color='pink')
Out[11]:

Secondary Axis

You can now use secondary_y in iplot to indicate if a given trace should be plotted in a secondary (right) axis

In [12]:
lines=cf.datagen.lines(4,mode='abc')

# We multiply 2 of the 4 lines by 100
lines[['c','d']]=lines[['c','d']]*100

#If we plot the resulting DataFrame then we get the following chart
lines.iplot()
Out[12]:
In [13]:
# We can however move those lines to the secondary axis

lines.iplot(kind='lines',secondary_y=['c','d'])
Out[13]:

Logarithmic Charts

iplot now support logarithmic charts for boths Y and X axis, by using logy=True and logx=True respectively

In [14]:
df=pd.DataFrame([x**2] for x in range(100))
In [15]:
df.iplot()
Out[15]:
In [16]:
df.iplot(logy=True)
Out[16]:

Support for Multi-Index DataFrames

In [17]:
ix3 = pd.MultiIndex.from_arrays([['a', 'a', 'a', 'a', 'b', 'b', 'b', 'b'], ['foo', 'foo', 'bar', 'bar', 'foo', 'foo', 'bar', 'bar']], names=['letter', 'word'])
df3 = pd.DataFrame({'data1': [3, 2, 4, 3, 2, 4, 3, 2], 'data2': [6, 5, 7, 5, 4, 5, 6, 5]}, index=ix3)
gp3 = df3.groupby(level=('letter', 'word'))
means = gp3.mean()
In [18]:
means
Out[18]:
data1 data2
letter word
a bar 3.5 6.0
foo 2.5 5.5
b bar 2.5 5.5
foo 3.0 4.5
In [19]:
means.iplot(kind='bar')
Out[19]:

Error Bars

You can now add error bars in scatter,bar and line charts by passing the errors to error_y and error_x to iplot.

In [20]:
cf.datagen.lines(1,5).iplot(kind='bar',error_y=[1,2,3.5,2,2])
Out[20]:

There are more type of error bars which can be set with error_type: data,constant,percent,sqrt
To see more info regarding each of them check help(cf.ErrorY)

In [21]:
# 20% error bars
cf.datagen.bars().iplot(kind='bar',error_y=20,error_type='percent',error_color='red')
Out[21]:

Continuous Error Bars

Continous error bars (shades) can also be plotted with error_type='continuous' or error_type='continuous_percent'

In [22]:
# Line chart with a tolerance of 20%
cf.datagen.lines(1).iplot(kind='scatter',error_y=20,error_type='continuous_percent')
Out[22]:
In [23]:
# Line chart with an error of 10 
cf.datagen.lines(1).iplot(kind='scatter',error_y=10,error_type='continuous',color='blue')
Out[23]:

Technical Analysis (Beta)

Cufflinks v0.6.0 includes a set of Technical Analysis studies for financial data.

These are accessed with a new method called ta_plot.

Simple Moving Averages

One or more moving averages can be added to a time series.

In [24]:
cf.datagen.lines(1,500).ta_plot(study='sma',periods=[13,21,55],title='Simple Moving Averages')
Out[24]:

Bollinger Bands

These are a volatility indicator - and tell us the number the distance of the current value (at a given point) to the N number of standard deviations.

In [25]:
cf.datagen.lines(1,200).ta_plot(study='boll',periods=14,title='Bollinger Bands')
Out[25]:

Relative Strength Index (RSI)

The relative strength index tells the historical strength or weakness of the historial price.

In [52]:
cf.datagen.lines(1,200).ta_plot(study='rsi',periods=14,title='Relative Strength Index')
Out[52]:

Moving Average Convergence Divergence (MACD)

A trend-following momentum indicator that shows the relationship between two moving averages of prices.

In [53]:
cf.datagen.lines(1,200).ta_plot(study='macd',fast_period=12,slow_period=26,
                                signal_period=9)
Out[53]:
In [ ]: