@@ -511,8 +511,10 @@ def create_ohlc(open, high, low, close,
511
511
512
512
import pandas.io.data as web
513
513
514
- df = web.DataReader("aapl", 'yahoo', datetime(2008, 8, 15), datetime(2008, 10, 15))
515
- fig = FF.create_ohlc(df.Open, df.High, df.Low, df.Close, dates=df.index)
514
+ df = web.DataReader("aapl", 'yahoo', datetime(2008, 8, 15),
515
+ datetime(2008, 10, 15))
516
+ fig = FF.create_ohlc(df.Open, df.High, df.Low, df.Close,
517
+ dates=df.index)
516
518
517
519
py.plot(fig, filename='finance/aapl-ohlc')
518
520
```
@@ -525,10 +527,12 @@ def create_ohlc(open, high, low, close,
525
527
526
528
import pandas.io.data as web
527
529
528
- df = web.DataReader("aapl", 'yahoo', datetime(2008, 8, 15), datetime(2008, 10, 15))
529
- fig = FF.create_ohlc(df.Open, df.High, df.Low, df.Close, dates=df.index)
530
+ df = web.DataReader("aapl", 'yahoo', datetime(2008, 8, 15),
531
+ datetime(2008, 10, 15))
532
+ fig = FF.create_ohlc(df.Open, df.High, df.Low, df.Close,
533
+ dates=df.index)
530
534
531
- # Update the fig - all options here: https://plot.ly/python/reference/#Layout
535
+ # Update the fig - See https://plot.ly/python/reference/#Layout
532
536
fig['layout'].update({
533
537
'title': 'The Great Recession',
534
538
'yaxis': {'title': 'AAPL Stock'},
@@ -557,17 +561,20 @@ def create_ohlc(open, high, low, close,
557
561
558
562
import pandas.io.data as web
559
563
560
- df = web.DataReader("aapl", 'yahoo', datetime(2008, 1, 1), datetime(2009, 4, 1))
564
+ df = web.DataReader("aapl", 'yahoo', datetime(2008, 1, 1),
565
+ datetime(2009, 4, 1))
561
566
562
567
# Make increasing ohlc sticks and customize their color and name
563
- fig_increasing = FF.create_ohlc(df.Open, df.High, df.Low, df.Close, dates=df.index,
568
+ fig_increasing = FF.create_ohlc(df.Open, df.High, df.Low, df.Close,
569
+ dates=df.index,
564
570
direction='increasing', name='AAPL',
565
571
line=Line(color='rgb(150, 200, 250)'))
566
572
567
573
# Make decreasing ohlc sticks and customize their color and name
568
- fig_decreasing = FF.create_ohlc(df.Open, df.High, df.Low, df.Close, dates=df.index,
569
- direction='decreasing',
570
- line=Line(color='rgb(128, 128, 128)'))
574
+ fig_decreasing = FF.create_ohlc(df.Open, df.High, df.Low, df.Close,
575
+ dates=df.index,
576
+ direction='decreasing',
577
+ line=Line(color='rgb(128, 128, 128)'))
571
578
572
579
# Initialize the figure
573
580
fig = fig_increasing
@@ -608,7 +615,7 @@ def create_ohlc(open, high, low, close,
608
615
else :
609
616
FigureFactory ._validate_equal_length (open , high , low , close )
610
617
FigureFactory ._validate_ohlc (open , high , low , close , direction ,
611
- ** kwargs )
618
+ ** kwargs )
612
619
613
620
if direction is 'increasing' :
614
621
ohlc_incr = FigureFactory ._make_increasing_ohlc (open , high ,
@@ -750,15 +757,18 @@ def create_candlestick(open, high, low, close,
750
757
751
758
import pandas.io.data as web
752
759
753
- df = web.DataReader("aapl", 'yahoo', datetime(2007, 10, 1), datetime(2009, 4, 1))
754
- fig = FF.create_candlestick(df.Open, df.High, df.Low, df.Close, dates=df.index)
760
+ df = web.DataReader("aapl", 'yahoo', datetime(2007, 10, 1),
761
+ datetime(2009, 4, 1))
762
+ fig = FF.create_candlestick(df.Open, df.High, df.Low, df.Close,
763
+ dates=df.index)
755
764
py.plot(fig, filename='finance/aapl-candlestick', validate=False)
756
765
```
757
766
758
767
Example 2: Add text and annotations to the candlestick chart
759
768
```
760
- fig = FF.create_candlestick(df.Open, df.High, df.Low, df.Close, dates=df.index)
761
- # Update the fig - all options here: https://plot.ly/python/reference/#Layout
769
+ fig = FF.create_candlestick(df.Open, df.High, df.Low, df.Close,
770
+ dates=df.index)
771
+ # Update the fig - See https://plot.ly/python/reference/#Layout
762
772
fig['layout'].update({
763
773
'title': 'The Great Recession',
764
774
'yaxis': {'title': 'AAPL Stock'},
@@ -773,7 +783,8 @@ def create_candlestick(open, high, low, close,
773
783
'text': 'Official start of the recession'
774
784
}]
775
785
})
776
- py.plot(fig, filename='finance/aapl-recession-candlestick', validate=False)
786
+ py.plot(fig, filename='finance/aapl-recession-candlestick',
787
+ validate=False)
777
788
```
778
789
779
790
Example 3: Customize the candlestick colors
@@ -785,27 +796,32 @@ def create_candlestick(open, high, low, close,
785
796
786
797
import pandas.io.data as web
787
798
788
- df = web.DataReader("aapl", 'yahoo', datetime(2008, 1, 1), datetime(2009, 4, 1))
799
+ df = web.DataReader("aapl", 'yahoo', datetime(2008, 1, 1),
800
+ datetime(2009, 4, 1))
789
801
790
802
# Make increasing candlesticks and customize their color and name
791
- fig_increasing = FF.create_candlestick(df.Open, df.High, df.Low, df.Close, dates=df.index,
803
+ fig_increasing = FF.create_candlestick(
804
+ df.Open, df.High, df.Low, df.Close, dates=df.index,
792
805
direction='increasing', name='AAPL',
793
806
marker=Marker(color='rgb(150, 200, 250)'),
794
- line=Line(color='rgb(150, 200, 250)'))
807
+ line=Line(color='rgb(150, 200, 250)')
808
+ )
795
809
796
810
# Make decreasing candlesticks and customize their color and name
797
- fig_decreasing = FF.create_candlestick(df.Open, df.High, df.Low, df.Close, dates=df.index,
798
- direction='decreasing',
799
- marker=Marker(color='rgb(128, 128, 128)'),
800
- line=Line(color='rgb(128, 128, 128)'))
811
+ fig_decreasing = FF.create_candlestick(
812
+ df.Open, df.High, df.Low, df.Close, dates=df.index,
813
+ direction='decreasing', marker=Marker(color='rgb(128, 128, 128)'),
814
+ line=Line(color='rgb(128, 128, 128)')
815
+ )
801
816
802
817
# Initialize the figure
803
818
fig = fig_increasing
804
819
805
820
# Add decreasing data with .extend()
806
821
fig['data'].extend(fig_decreasing['data'])
807
822
808
- py.iplot(fig, filename='finance/aapl-candlestick-custom', validate=False)
823
+ py.iplot(fig, filename='finance/aapl-candlestick-custom',
824
+ validate=False)
809
825
```
810
826
811
827
Example 4: Candlestick chart with datetime objects
@@ -838,7 +854,7 @@ def create_candlestick(open, high, low, close,
838
854
else :
839
855
FigureFactory ._validate_equal_length (open , high , low , close )
840
856
FigureFactory ._validate_ohlc (open , high , low , close , direction ,
841
- ** kwargs )
857
+ ** kwargs )
842
858
843
859
if direction is 'increasing' :
844
860
candle_incr_data = FigureFactory ._make_increasing_candle (
@@ -1075,8 +1091,8 @@ def create_dendrogram(X, orientation="bottom", labels=None,
1075
1091
_scipy__cluster__hierarchy_imported )
1076
1092
1077
1093
if dependencies is False :
1078
- raise ImportError ("FigureFactory.create_dendrogram requires scipy, \
1079
- scipy.spatial and scipy.hierarchy" )
1094
+ raise ImportError ("FigureFactory.create_dendrogram requires "
1095
+ "scipy, scipy.spatial and scipy.hierarchy" )
1080
1096
1081
1097
s = X .shape
1082
1098
if len (s ) != 2 :
@@ -1317,8 +1333,9 @@ def g(xi, yi):
1317
1333
vi = self .value_at (self .v , xi , yi )
1318
1334
return - ui * dt_ds , - vi * dt_ds
1319
1335
1320
- check = lambda xi , yi : (0 <= xi < len (self .x ) - 1 and
1321
- 0 <= yi < len (self .y ) - 1 )
1336
+ def check (xi , yi ):
1337
+ return 0 <= xi < len (self .x ) - 1 and 0 <= yi < len (self .y ) - 1
1338
+
1322
1339
xb_changes = []
1323
1340
yb_changes = []
1324
1341
@@ -1579,8 +1596,8 @@ def get_increase(self):
1579
1596
flat_increase_x = FigureFactory ._flatten (self .increase_x )
1580
1597
flat_increase_y = FigureFactory ._flatten (self .increase_y )
1581
1598
text_increase = (("Open" , "Open" , "High" ,
1582
- "Low" , "Close" , "Close" , '' )
1583
- * (len (self .increase_x )))
1599
+ "Low" , "Close" , "Close" , '' ) *
1600
+ (len (self .increase_x )))
1584
1601
1585
1602
return flat_increase_x , flat_increase_y , text_increase
1586
1603
@@ -1595,8 +1612,8 @@ def get_decrease(self):
1595
1612
flat_decrease_x = FigureFactory ._flatten (self .decrease_x )
1596
1613
flat_decrease_y = FigureFactory ._flatten (self .decrease_y )
1597
1614
text_decrease = (("Open" , "Open" , "High" ,
1598
- "Low" , "Close" , "Close" , '' )
1599
- * (len (self .decrease_x )))
1615
+ "Low" , "Close" , "Close" , '' ) *
1616
+ (len (self .decrease_x )))
1600
1617
1601
1618
return flat_decrease_x , flat_decrease_y , text_decrease
1602
1619
@@ -1736,8 +1753,8 @@ def make_kde(self):
1736
1753
curve = [None ] * self .trace_number
1737
1754
for index in range (self .trace_number ):
1738
1755
self .curve_x [index ] = [self .start [index ] +
1739
- x * (self .end [index ] - self .start [index ])
1740
- / 500 for x in range (500 )]
1756
+ x * (self .end [index ] - self .start [index ]) /
1757
+ 500 for x in range (500 )]
1741
1758
self .curve_y [index ] = (scipy .stats .gaussian_kde
1742
1759
(self .hist_data [index ])
1743
1760
(self .curve_x [index ]))
@@ -1772,8 +1789,8 @@ def make_normal(self):
1772
1789
mean [index ], sd [index ] = (scipy .stats .norm .fit
1773
1790
(self .hist_data [index ]))
1774
1791
self .curve_x [index ] = [self .start [index ] +
1775
- x * (self .end [index ] - self .start [index ])
1776
- / 500 for x in range (500 )]
1792
+ x * (self .end [index ] - self .start [index ]) /
1793
+ 500 for x in range (500 )]
1777
1794
self .curve_y [index ] = scipy .stats .norm .pdf (
1778
1795
self .curve_x [index ], loc = mean [index ], scale = sd [index ])
1779
1796
self .curve_y [index ] *= self .bin_size
0 commit comments