[Matplotlib-users] Totaly new to matplotlib

Stevo stm6386 at gmail.com
Thu Feb 4 12:36:22 EST 2016


Paul,
Thanks for the reply, since my last post I've been working on this lots and
have a working script.
Pictures below, took me a while to get it working but it does. the main
issue I have with it is that as you can see from the pictures when the time
periods for a day are stacked for some reason the are all on a slant
(presumably time related)
<http://matplotlib.1069221.n5.nabble.com/file/n46709/figure_2.png> 
<http://matplotlib.1069221.n5.nabble.com/file/n46709/figure_3.png> 

Is there a way to straighten it all up ?
as in the script below it now receives ['3/6/2013' '11:30:00' '14:30:00'
'3:00:00'] for each event, the basics are there but its not very pretty yet.
Im still trying to figure out how I got it working  quite an achievement for
me if i#m honest.
code
def createGraph(self):
        #data appears like so:
        #date,init time,end time,elapsed time
        #3/6/2013,4:30:00,8:45:00,4:15:00
        try:
            data =  np.array(self.graphList1)    
            #print data[1]
            #['3/6/2013' '11:30:00' '14:30:00' '3:00:00']
            day = data[:,0]
            hour1 = data[:,1]
            hour2 = data[:,2]
            hour3 = data[:,3]
           
            inittime = [a+' '+b for a,b in zip(day, hour1)]
            elapsedtime = [a+' '+b for a,b in zip(day, hour3)]
            #print inittime
            # 3/6/2013 4:30:00
        except Exception, e:
            print e        
       
       
        #from [1], " I gave up after trying a few different ways, and
resorted to a very easy workaround.
        # Plot the times as integer minutes : 0 being midnight, 60 = 1am ...
which is 24hr * 60. "
        def dt2m(dt):
            return (dt.hour*60) + dt.minute
           
        print inittime[0]
       
        inittime = [datetime.datetime.strptime(foo,'%d/%m/%Y %H:%M') for foo
in inittime]
        elapsedtime = [datetime.datetime.strptime(foo,'%d/%m/%Y %H:%M:%S')
for foo in elapsedtime]
        #os.remove('chart.csv')
        # [1] "Then format the Y axis as Hour:Minute using a custom
formatter:"
        def m2hm(x, i):
            h = int(x/60)
            m = int(x%60)
            return '%(h)02d:%(m)02d' % {'h':h,'m':m}
       
        inittime_mins = [dt2m(foo) for foo in inittime]
        elaptime_mins = [dt2m(foo) for foo in elapsedtime]
        #heights = [60,120,240]
        #print inittime_mins
       
       
        fig = plt.figure(figsize=(12,7)) #figsize in inches
        ax = fig.add_subplot(1, 1, 1)
        ax.bar(inittime,elaptime_mins,bottom=inittime_mins)
       
        plt.xticks(rotation='45')
       
        # matplotlib date format object
        hfmt = dates.DateFormatter('%b %d')
        ax.xaxis.set_major_formatter(hfmt)
        ax.xaxis.set_major_locator(plt.MultipleLocator(1.0)) #a tick mark a
day
       
       
        ax.set_ylim([20*60, 5*60])
        ax.yaxis.set_major_formatter(ff(m2hm))
        ax.yaxis.set_major_locator(plt.MultipleLocator(60)) #a tick mark an
hour
        plt.subplots_adjust (left = 0.06, bottom = 0.10, right = 0.97, top =
0.97, wspace = 0.20, hspace = 0.20)
        plt.show()code 



--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Totaly-new-to-matplotlib-tp46682p46709.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


More information about the Matplotlib-users mailing list