@@ -0,0 +1,2098 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4%0A%0A# Copyright 2013 Jason Koelker%0A#%0A#  Licensed under the Apache License, Version 2.0 (the %22License%22);%0A#  you may not use this file except in compliance with the License.%0A#  You may obtain a copy of the License at%0A#%0A#      http://www.apache.org/licenses/LICENSE-2.0%0A#%0A#  Unless required by applicable law or agreed to in writing, software%0A#  distributed under the License is distributed on an %22AS IS%22 BASIS,%0A#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A#  See the License for the specific language governing permissions and%0A#  limitations under the License.%0A%0Aimport pylab%0A%0Afrom matplotlib import finance%0Afrom matplotlib import transforms%0A%0A%0Adef offset(ax, x, y):%0A    return transforms.offset_copy(ax.transData, x=x, y=y, units='dots')%0A%0A%0Adef label_bar(ax, label, bar, above=False):%0A    trans = offset(ax, 0, -12.5)%0A    x = bar%5B0%5D%0A    y = bar%5B4%5D%0A    if above:%0A        trans = offset(ax, 0, 5)%0A        y = bar%5B3%5D%0A        ax.text(x, y, label, transform=trans)%0A%0A%0Adef plot_setup(signal, date_strfmt='%25b-%25d'):%0A    fig = pylab.figure(figsize=(16, 9))%0A    fig.subplots_adjust(bottom=0.2)%0A%0A    ax = fig.add_subplot(111)%0A    ax.margins(0.05, 0.05)%0A%0A    bars = signal%5B'flip'%5D%5B'bars'%5D + signal%5B'bars'%5D%0A    bars = %5B%5Bb%5B'dt'%5D.to_pydatetime(), b%5B'open'%5D,%0A             b%5B'close'%5D, b%5B'high'%5D, b%5B'low'%5D%5D for b in bars%5D%0A%0A    ax.set_xticks(range(0, len(bars)))%0A    ax.set_xticklabels(%5Bbars%5Bi%5D%5B0%5D.strftime(date_strfmt)%0A                        for i in ax.get_xticks()%5D)%0A%0A    plot_bars = %5B%5Bi%5D + bar%5B1:%5D for i, bar in enumerate(bars)%5D%0A%0A    finance.plot_day_summary(ax, plot_bars)%0A%0A    flip_end = len(signal%5B'flip'%5D%5B'bars'%5D) - 1%0A    label_bar(ax, 'X', plot_bars%5B0%5D, True)%0A    label_bar(ax, 'Y', plot_bars%5B1%5D, True)%0A    label_bar(ax, %22X'%22, plot_bars%5Bflip_end - 1%5D, True,)%0A    label_bar(ax, %22Y'%22, plot_bars%5Bflip_end%5D, True)%0A%0A    for i, bar in enumerate(plot_bars%5Bflip_end:%5D, 1):%0A        label_bar(ax, i, bar)%0A%0A    ax.autoscale_view()%0A    pylab.setp(pylab.gca().get_xticklabels(), rotation=45,%0A               horizontalalignment='right')%0A    pylab.show()%0A

Add plotting utils