Hi All

i'm bring to do  simple bar plot formatting the xlabe as 'date' using a syntax 
like :  fig.autofmt_xdate(bottom=0.1) 
but something is wrong in my code, please have you any hints on ghow to proper 
display the dates (Year) along the x axis
and how to leave a margin on the left and on the right of the plot?   (my 
example has a margin only on the right, while the first bar is adjacent to the 
Y axis)

 
###

import numpy as np
import matplotlib.pyplot as plt

x = np.array([1969,1970,1971,1972,1973,1974])
y = np.array([-3,10,23,-4,-5,6])
data = [x,y]

print x
print y




def bar_plot(data, Yval, datamin=None, datamax=None):
    """ doc """ 
    fig = plt.figure()
    fig.autofmt_xdate(bottom=0.1) 
    ax1 = fig.add_subplot(211)
    x = data[0]
    y = data[1]
    if datamin != datamax != None :
        x = data[0][np.where((data[0]>=datamin) & (data[0]<=datamax))[0]]
        y = data[1][np.where((data[0]>=datamin) & (data[0]<=datamax))[0]]
    x_p = x[np.where(y>=0)[0]]
    y_p = y[np.where(y>=0)[0]]
    x_n = x[np.where(y<0)[0]]
    y_n = y[np.where(y<0)[0]]
    ax1.bar(x_n, y_n, facecolor='b') 
    ax1.bar(x_p, y_p, facecolor='r') 
    ax1.grid(True)
    ax1.set_xlabel('Year')
    ax1.set_ylabel(Yval)
    ax1.set_title(Yval)
    ax1.axhline(0, color='black', lw=1)
    plt.show()
    
bar_plot(data, 'Var', datamin=1970, datamax=1973)

###
------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to