As was suggested by Jae-Joon, I have simplified the code for easier investigation and run. The aim of the script is to have time represented on both bottom and top x-axes, on the bottom in seconds-from-midnight (SFM), and the top should show as HH:MM:SS, while there is two different data source being used for y-axes. The code could be seen here or from http://code.google.com/p/ccnworks/source/browse/trunk/double_time.py
Currently something wrong with the scaling, since the right y-axis data is missing on the plotting area. Also, sfm hasn’t been converted to HH:MM:SS. adding this: par.xaxis.set_major_formatter(DateFormatter(’%H:%M:%S’)) doesn’t remedy the situation as of yet.
All comments are welcome.
Double time representation. Bottom x-axis shows time in seconds-from-midnight
(sfm) fashion, whereas the top x-axis uses HH:MM:SS representation.
Initially written by Gokhan Sever with helps from Jae-Joon Lee.
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.transforms as mtransforms
from mpl_toolkits.axes_grid.parasite_axes import SubplotHost
Prepare some random data and time for seconds-from-midnight (sfm) representation
ydata1 = np.random.random(100) * 1000
ydata2 = np.ones(100) / 2.
time = np.arange(3550, 3650)
fig = plt.figure()
host = SubplotHost(fig, 111)
This is the heart of the example. We have to scale the axes correctly.
aux_trans = mtransforms.Affine2D().translate(0., 0.).scale(3600, ydata1.max())
par = host.twin(aux_trans)
host.set_ylabel(“Random Data 1”)
par.set_ylabel(“Random Data 2”)
p1, = host.plot(time, ydata1)
p2, = par.plot(time, ydata2)
Move the title little upwards so it won’t overlap with the ticklabels
title = plt.title(“Double time: SFM and HH:MM:SS”, fontsize=18)