import cufflinks as cf
import pandas as pd
%reload_ext autoreload
%autoreload 2
cf.set_config_file(world_readable=True,offline=False)
datagen can now generate a DataFrame
with the structured required for a pie charts
pie=cf.datagen.pie()
pie.head()
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
pie.iplot(kind='pie',labels='labels',values='values')
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
pie.iplot(kind='pie',labels='labels',values='values',pull=.2,hole=.2,
colorscale='blues',textposition='outside',textinfo='value+percent')
datagen now includes a method ohlc
to generate Open, High, Low, Close data
ohlc=cf.datagen.ohlc()
ohlc.head()
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 |
ohlc.iplot()
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
.
ohlc.iplot(kind='ohlc')
ohlc.head().iplot(kind='candle',theme='ggplot',up_color='blue',down_color='pink')
You can now use secondary_y
in iplot
to indicate if a given trace should be plotted in a secondary (right) axis
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()
# We can however move those lines to the secondary axis
lines.iplot(kind='lines',secondary_y=['c','d'])
iplot
now support logarithmic charts for boths Y and X axis, by using logy=True
and logx=True
respectively
df=pd.DataFrame([x**2] for x in range(100))
df.iplot()
df.iplot(logy=True)
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()
means
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 |
means.iplot(kind='bar')
You can now add error bars in scatter,bar and line charts by passing the errors to error_y
and error_x
to iplot
.
cf.datagen.lines(1,5).iplot(kind='bar',error_y=[1,2,3.5,2,2])
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)
# 20% error bars
cf.datagen.bars().iplot(kind='bar',error_y=20,error_type='percent',error_color='red')
Continous error bars (shades) can also be plotted with error_type='continuous'
or error_type='continuous_percent'
# Line chart with a tolerance of 20%
cf.datagen.lines(1).iplot(kind='scatter',error_y=20,error_type='continuous_percent')
# Line chart with an error of 10
cf.datagen.lines(1).iplot(kind='scatter',error_y=10,error_type='continuous',color='blue')
Cufflinks v0.6.0 includes a set of Technical Analysis studies for financial data.
These are accessed with a new method called ta_plot.
One or more moving averages can be added to a time series.
cf.datagen.lines(1,500).ta_plot(study='sma',periods=[13,21,55],title='Simple Moving Averages')
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.
cf.datagen.lines(1,200).ta_plot(study='boll',periods=14,title='Bollinger Bands')
The relative strength index tells the historical strength or weakness of the historial price.
cf.datagen.lines(1,200).ta_plot(study='rsi',periods=14,title='Relative Strength Index')
A trend-following momentum indicator that shows the relationship between two moving averages of prices.
cf.datagen.lines(1,200).ta_plot(study='macd',fast_period=12,slow_period=26,
signal_period=9)