示例#1
0
def test_PlotterScatter():
    """
    Test class ``PlotterLine``.
    
    TODO: assertions. Look at Matplotlib tests.
          http://matplotlib.org/devel/testing.html
    """
    from clair.diagram import PlotterScatter, FilterContains
    
    print("Start")
    
    #Create a data frame with random prices and times
    prices = create_test_prices()
    prices = FilterContains("product", "foo", True).filter(prices)
    prices = prices.sort("time")
    
    #Create the objects for Matplotlib
    fig = plt.figure()
    
    #Test line plot
    ax = fig.add_subplot(2, 1, 1)
    graph = PlotterScatter()
    graph.plot(ax, prices["time"], prices["price"])
    
    #Test scatter plot
    ax = fig.add_subplot(2, 1, 2)
    graph = PlotterScatter(saturation=0.5, marker="p", color="orange", 
                           markersize=7)
    graph.plot(ax, prices["time"], prices["price"])

    fig.autofmt_xdate()
    plt.show()
    print("End")
示例#2
0
def test_PlotterLine():
    """
    Test class ``PlotterLine``.
    
    TODO: assertions. Look at Matplotlib tests.
          http://matplotlib.org/devel/testing.html
    """
    from clair.diagram import PlotterLine, FilterContains, PlotterScatter
    
    print("Start")
    
    #Create a data frame with random prices and times
    prices = create_test_prices()
    prices = FilterContains("product", "foo", True).filter(prices)
    prices = prices.sort("time")
    
    #Create the objects for Matplotlib
    fig = plt.figure()
    
    #Test line plot
    ax = fig.add_subplot(3, 1, 1)
    graph = PlotterLine()
    graph.plot(ax, prices["time"], prices["price"])
    
    #Compute average and standard deviation
    monthly = pd.TimeGrouper(freq="M")
    prices_t = prices.set_index("time")
    prices_s = prices_t.groupby(monthly).aggregate([np.mean, np.std])
#    print prices_s
    
    #Test limit display: filled
    ax = fig.add_subplot(3, 1, 2)
    graph_mean = PlotterLine(markersize=7, fill_limits=True)
    graph_mean.plot(ax, prices_s.index, 
                    prices_s["price"]["mean"], prices_s["price"]["std"],)
#    #Plot scatter plot on top, to see how they look together
    scatter = PlotterScatter(saturation=0.5)
    scatter.plot(ax, prices["time"], prices["price"]) 
    
    #Test limit display: lines
    ax = fig.add_subplot(3, 1, 3)
    graph_mean = PlotterLine(markersize=7, fill_limits=False)
    graph_mean.plot(ax, prices_s.index, 
                    prices_s["price"]["mean"], prices_s["price"]["std"],)
#    #Plot scatter plot on top, to see how they look together
    scatter = PlotterScatter(saturation=0.5)
    scatter.plot(ax, prices["time"], prices["price"]) 
    
    fig.autofmt_xdate()
    plt.show()
    print("End")