473,383 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

matplotlib: Plotting a graph against time

Hi,

I'm trying to plot a simple graph against date or time using matplotlib. I've read about date_plot but I'm not really sure how to use it. At the moment, I have some data arranged into lists, where list1 contains x values (time) and list2 contains y values just like is needed for the normal plot function. The time values are simply the output of datetime.date.today(), etc which I don't mind changing the format of.

My question is, how do I plot the graph with list1 on the x axis and list2 on the y axis. Using plot and unixtime I get a very ugly scale as is to be expected so I want to know how to use the date_plot function efficiently. At the moment, I'm only concerned about the actual plotting but help with Locater Ticks (Months and Years) is also very appreciated.

Thanks a lot!
Jul 19 '08 #1
2 6380
On Jul 19, 3:09*pm, Durand <dura...@gmail.comwrote:
Hi,

I'm trying to plot a simple graph against date or time using matplotlib. I've read about date_plot but I'm not really sure how to use it. At the moment, I have some data arranged into lists, where list1 contains x values (time) and list2 contains y values just like is needed for the normal plot function. The time values are simply the output of datetime.date.today(), etcwhich I don't mind changing the format of.

My question is, how do I plot the graph with list1 on the x axis and list2 on the y axis. Using plot and unixtime I get a very ugly scale as is to be expected so I want to know how to use the date_plot function efficiently.At the moment, I'm only concerned about the actual plotting but help with Locater Ticks (Months and Years) is also very appreciated.

Thanks a lot!

I'm not sure if this is what you're looking for, but here's a quick
sample that uses plot_date to plot some random values.

import pylab, random
from datetime import datetime, timedelta

today = datetime.now()

dates = [today + timedelta(days=i) for i in range(10)]
values = [random.randint(1, 20) for i in range(10)]
pylab.plot_date(pylab.date2num(dates), values, linestyle='-')
Jul 20 '08 #2
On Jul 20, 8:55*am, arsyed <ars...@gmail.comwrote:
On Jul 19, 3:09*pm, Durand <dura...@gmail.comwrote:
Hi,
I'm trying to plot a simple graph against date or time using matplotlib.. I've read about date_plot but I'm not really sure how to use it. At the moment, I have some data arranged into lists, where list1 contains x values (time) and list2 contains y values just like is needed for the normal plot function. The time values are simply the output of datetime.date.today(), etc which I don't mind changing the format of.
My question is, how do I plot the graph with list1 on the x axis and list2 on the y axis. Using plot and unixtime I get a very ugly scale as is tobe expected so I want to know how to use the date_plot function efficiently. At the moment, I'm only concerned about the actual plotting but help with Locater Ticks (Months and Years) is also very appreciated.
Thanks a lot!

I'm not sure if this is what you're looking for, but here's a quick
sample that uses plot_date to plot some random values.

import pylab, random
from datetime import datetime, timedelta

today = datetime.now()

dates = [today + timedelta(days=i) for i in range(10)]
values = [random.randint(1, 20) for i in range(10)]
pylab.plot_date(pylab.date2num(dates), values, linestyle='-')
Oooh, this is almost what I want but I'm not really sure how I'd
incorporate this into real dates...
If I have a list of dates like ['2008-07-18 14:36:53.494013',
'2008-07-20 14:37:01.508990', '2008-07-28 14:49:26.183256'], how would
I convert it to a format that pylab can understand? When I tried
type(datetime.now()) it gave me datetime.datetime whereas the objects
in this list are strings...Am I doing something wrong here?
Jul 20 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: John Hunter | last post by:
matplotlib is a 2D plotting package for python with a matlab compatible syntax and output tested under linux and windows platforms. matplotlib-0.30 is available for download at...
3
by: John Hunter | last post by:
matplotlib is a 2D plotting library for python. You can use matplotlib interactively from a python shell or IDE, or embed it in GUI applications (WX, GTK, and Tkinter). matplotlib supports many...
1
by: Jorl Shefner | last post by:
I've only been able to plot data with both symbols and lines by issuing two plot commands, one for markers and one for lines. That's perfectly fine, but it creates a problem when I try to create a...
8
by: fortuneteller | last post by:
Hello, I'm quite new to python and Scipy. Anyway I want to use it to plot graphs. Does anybody know if there is the possibility to use Latex in SciPy's plotting functions like gplt? Thanks...
2
by: bwaha | last post by:
Has anyone figured out how to get a legend for each line in a matplotlib.collections.LineCollection instance? No problem if I plot lines the default way ie. line,=plot(x,y). But I've had to...
0
by: OKB (not okblacke) | last post by:
I just downloaded matplotlib and I was trying to do some simple date plots, but I'm running up against a puzzling error. Whenever I attempt to plot dates, I get an exception on line 157 of...
4
by: Bill Jackson | last post by:
Hi, I'm having some trouble plotting with the following matplotlibrc: text.usetex : True I tried clearing the cache files under ~/.matplotlib, but this did not help the problem. I'd post...
2
by: Magdoll | last post by:
Has anyone run into the same problem I have? I used to run matplotlib with Python2.5 and everything worked fine. Now I use Python2.6, and everything falls apart. I installed numpy, libpng, and...
2
by: sharath067 | last post by:
I want to dynamically update the scatter plot based on the y-axis data received from a socket connection. I used python matplot lib in interactive mode to do this, but during dynamic updation if i...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.