Issues with time display

Hi,

I've managed to take the contents of my CSV file and display it with
matplotlib. I'm having some issues with the way my X-axis is being
displayed.

For the X-axis, I pass in a list that filled with datetime objects, an
example of one element on the list:

datetime.datetime(2007, 12, 17, 20, 28, 15),

Issues (please see the attached cpu.png:

- for some reason a TZ has been inserted
- graphs have white space buffers on either side of the X-axix
- points on X-axis are separated by the hour, instead of values in datetime
object

I have tried many variations of plotdate, etc. If someone could please point
me in the right direction.

Thanks

···

=================
Code http://www.nabble.com/file/p21958283/cpu.png

#!/usr/bin/env python

import csv
import sys
import matplotlib.pyplot as plt
import datetime

new_list = []
time = []
cpu = []

fileReader = csv.reader(open("sample.csv", "rb"))
for row in fileReader:
    new_list.append(row)

# Converts papatimes time format into dattime
def time_split(current_line):
    # splits papastats datetime format in useable python list
    dt = datetime.datetime.strptime(current_line[0],"%Y/%m/%d %H:%M:%S")
    time.append(dt)

def cpu_calc(current_line):
    cpu.append(current_line[11].rstrip("%"))

#Iterate over list of CSV values
for i in new_list[1:]:
    time_split(i)
    cpu_calc(i)

plt.plot(time, cpu, 'b-')
#plt.plot_date(time, cpu, fmt='b-', xdate=False, ydate=False, tz=None)

plt.xlabel('Time')
plt.ylabel('CPU %')
plt.title('Daily CPU Usage')
plt.grid(True)
plt.grid(alpha=0.2, color='black', linestyle='-', linewidth=0.1)
plt.show()

--
View this message in context: http://www.nabble.com/Issues-with-time-display-tp21958283p21958283.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Hi clolern2,

- for some reason a TZ has been inserted

Datetime values are stored as numbers. Timezone info is added when that numbers are converted again into datetimes for labelling.

- graphs have white space buffers on either side of the X-axix

You can use axes.xlim in order to adjust it.

- points on X-axis are separated by the hour, instead of values in datetime
object

Matplotlib automagically chooses a format depending on the scale but you
can specify a format:

import matplotlib.dates as mdates
...
xaxis.set_major_formatter(mdates.DateFormatter('%Y-%b-%d %H:%M'))

Goyo

···

El mié, 11-02-2009 a las 09:38 -0800, collern2 escribió:

Hi,

I've managed to take the contents of my CSV file and display it with
matplotlib. I'm having some issues with the way my X-axis is being
displayed.

For the X-axis, I pass in a list that filled with datetime objects, an
example of one element on the list:

datetime.datetime(2007, 12, 17, 20, 28, 15),

Issues (please see the attached cpu.png:

- for some reason a TZ has been inserted
- graphs have white space buffers on either side of the X-axix
- points on X-axis are separated by the hour, instead of values in datetime
object

I have tried many variations of plotdate, etc. If someone could please point
me in the right direction.

Thanks

=================
Code http://www.nabble.com/file/p21958283/cpu.png

#!/usr/bin/env python

import csv
import sys
import matplotlib.pyplot as plt
import datetime

new_list =
time =
cpu =

fileReader = csv.reader(open("sample.csv", "rb"))
for row in fileReader:
    new_list.append(row)

# Converts papatimes time format into dattime
def time_split(current_line):
    # splits papastats datetime format in useable python list
    dt = datetime.datetime.strptime(current_line[0],"%Y/%m/%d %H:%M:%S")
    time.append(dt)

def cpu_calc(current_line):
    cpu.append(current_line[11].rstrip("%"))

#Iterate over list of CSV values
for i in new_list[1:]:
    time_split(i)
    cpu_calc(i)

plt.plot(time, cpu, 'b-')
#plt.plot_date(time, cpu, fmt='b-', xdate=False, ydate=False, tz=None)

plt.xlabel('Time')
plt.ylabel('CPU %')
plt.title('Daily CPU Usage')
plt.grid(True)
plt.grid(alpha=0.2, color='black', linestyle='-', linewidth=0.1)
plt.show()