Monday, July 4, 2011

How to plot biorhythm

The following script plot the biorhythm of a person born in 14/3/1988 in a range of 20 days.
from datetime import date
import matplotlib.dates
from pylab import *
from numpy import array,sin,pi

t0 = date(1988,3,14).toordinal()
t1 = date.today().toordinal()
t = array(range((t1-10),(t1+10))) # range of 20 days

y = 100*[sin(2*pi*(t-t0)/23),  # Physical
         sin(2*pi*(t-t0)/28),  # Emotional
         sin(2*pi*(t-t0)/33)]; # Intellectual

# converting ordinals to date
label = []
for p in t:
 label.append(date.fromordinal(p))

fig = figure()
ax = fig.gca()
plot(label,y[0],label,y[1],label,y[2])
# adding a legend
legend(['Physical', 'Emotional', 'Intellectual'])
# formatting the dates on the x axis
ax.xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%d/%b'))

show()
The resulting graph:

3 comments:

  1. I find this fascinating...
    Thanks for sharing.

    ReplyDelete
  2. this code is not working it is giving this error:
    ===================== RESTART: F:/python program/t.py ======================
    Traceback (most recent call last):
    File "F:/python program/t.py", line 2, in
    import matplotlib.dates
    ModuleNotFoundError: No module named 'matplotlib'
    >>> how can i fix it

    ReplyDelete
    Replies
    1. h, you have to install matplotblib first. This link can help: https://matplotlib.org/3.1.1/users/installing.html

      Delete

Note: Only a member of this blog may post a comment.