沒有官方的時間軸支持PYX呢。但是,您可以使用下面的代碼使其工作。不幸的是,你必須自己設置蜱和一個texter。
import time, datetime
from pyx import *
from pyx.graph.axis import timeaxis
from pyx.graph import data
# read the data with the first column being strings
d = data.file("timeaxis.dat", date=1, value=2)
# recreate the data while converting the date column to datetime
d = data.points([[datetime.datetime(*map(int, date.split('-'))), value]
for date, value in zip(d.columns["date"], d.columns["value"])], x=1, y=2)
g = graph.graphxy(height=5, x=timeaxis.timeaxis(manualticks=[timeaxis.timetick(2015, 11, 10),
timeaxis.timetick(2015, 11, 12),
timeaxis.timetick(2015, 11, 14),
timeaxis.timetick(2015, 11, 16),
timeaxis.timetick(2015, 11, 18),
timeaxis.timetick(2015, 11, 20)],
texter=timeaxis.timetexter("%b %d")))
g.plot(d)
g.writePDFfile()
這將導致以下的輸出:
你可以更改日期格式YYYY.MMDD? 如果是這樣,圖形模塊可能會讀取它,它仍然幾乎是你現在的格式。 –
py.p –