transformation de date en python

Pàgina inicial

Reply to this message
Autor: Vincent Kober
Data:  
A: guilde
Assumpte: transformation de date en python
Hello,

Pour construire un graph en python, j'ai
    fds = dates.date2num(dts)
et j'obtiens ensuite un array(je pense) que j'utilise dans la définition
de mon axe :
    plt.xticks(x, dts)


sauf que j'aimerai transformer cet array 2014/11/30 01:00:00, 2014/12/31
01:00:00, 2015/01/31 01:00:00, 2015/02/28 01:00:00

en ça et je sais pas faire (je découvre à peine python....)
2014/11/30, 2014/12/31, 2015/01/31, 2015/02/28

Je vous joint le fichier concerné au cas où....

Merci d'avance

VIncent



--
Vincent Kober
7 rue Pierre Giraud
38610 GIERES

04 76 89 30 76
06 69 13 87 04
vincent.kober@???
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import dates
import datetime

with plt.xkcd():
    # Based on "Stove Ownership" from XKCD by Randall Monroe
    # http://xkcd.com/418/


    fig = plt.figure()
    #ax = fig.add_axes((0.1, 0.2, 0.8, 0.7))
    ax = fig.add_subplot(111)


    ax.spines['right'].set_color('none')
    ax.spines['top'].set_color('none')



    x,y = np.loadtxt("donnees.txt", unpack=True)
    dd = np.loadtxt("donnees.txt", unpack=True)
    d = dd[:,0]
    #xx = datetime.datetime.strptime(x, "%Y%m%d")


    plt.plot(x,y)


    # convert epoch to matplotlib float format
    s = x
    #ms = x-1000*s  # not needed?
    dts = map(datetime.datetime.fromtimestamp, s)
    fds = dates.date2num(dts) # converted
    #dtsa = map(datetime.datetime.strptime(fds, "%Y%m%d"))


    #ss = datetime.datetime.strptime(x, '%Y%m%d')



    # matplotlib date format object
    hfmt = dates.DateFormatter('%Y%m%d')
    labelx = dts


    #x_lims = dates.date2num(dts)
    #ax.set_xlim = x_lims


    #ax.set_xlim(hfmt)
    ax.set_ylim([0, 250])
    plt.yticks([50,100,150,200,250])



    #ax.xaxis.set_major_locator(dates.MonthLocator())
    #ax.xaxis.set_major_formatter(hfmt)
    #ax.xaxis_date()


    ax.set_ylim(bottom = 0)
    plt.xticks(x, dts)
    plt.subplots_adjust(bottom=.5)






    #data = np.ones(100)
    #data[70:] -= np.arange(30)


    plt.annotate(
        '1er Forum ouvert',
        xy=(2, 100), arrowprops=dict(arrowstyle='->'), xytext=(3, 50))


    #plt.plot(data)


    plt.xlabel('en route vers alternatiba !')
    plt.ylabel('les forces en marche')
    fig.text(
        0.5, 0.05,
        '"ALTERNATIBA Grenoble, on y va !" par Kokonet',
        ha='center')


    #ax.xaxis_date()


    #date_format = dates.DateFormatter('%Y/%m-%d')


    #ax.xaxis.set_major_formatter(date_format)


    fig.autofmt_xdate()


plt.show()
1417305600 73
1419984000 95
1422662400 180
1425081600 190