Simplified version of double-axis time example (beta)

Hello,

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.

BEGIN CODE

#!/usr/bin/env python

“”"

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.

Written: 2009-09-27

“”"

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)
fig.add_subplot(host)

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_xlabel(“Time [sfm]”)
host.set_ylabel(“Random Data 1”)
par.set_ylabel(“Random Data 2”)
par.axis[“right”].label.set_visible(True)

p1, = host.plot(time, ydata1)

p2, = par.plot(time, ydata2)

host.axis[“left”].label.set_color(p1.get_color())
par.axis[“right”].label.set_color(p2.get_color())

host.axis[“bottom”].label.set_size(16)
host.axis[“left”].label.set_size(16)

par.axis[“right”].label.set_size(16)

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)
title.set_position((0.5, 1.05))

plt.show()

END CODE

···


Gökhan

Here is the modified version of your code that works for me.

1) If you change trans_aux, you also need to plot your data in an
appropriate coordinate. Your original code did not work because you
scaled the xaxis of the second axes (par) but you were still plotting
the original data, i.e., "time" need to be scaled if you want to plot
it on "par". The code below takes slightly different approach.

2) I fount that I was wrong with the factor of 3600. It needs to be
86400, i.e., a day in seconds. Also, The unit must be larger than 1.
Again, please take a look how datetime unit works.

Regards,

-JJ

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)
fig.add_subplot(host)

# 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_xlabel("Time [sfm]")
host.set_ylabel("Random Data 1")
par.set_ylabel("Random Data 2")
par.axis["right"].label.set_visible(True)

p1, = host.plot(time, ydata1)
p2, = par.plot(time, ydata2)

host.axis["left"].label.set_color(p1.get_color())
par.axis["right"].label.set_color(p2.get_color())

host.axis["bottom"].label.set_size(16)
host.axis["left"].label.set_size(16)
par.axis["right"].label.set_size(16)

# 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)
title.set_position((0.5, 1.05))

plt.show()

···

On Sun, Sep 27, 2009 at 12:32 PM, Gökhan Sever <gokhansever@...287...> wrote:

Hello,

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.

### BEGIN CODE ###
#!/usr/bin/env python

"""

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.

Written: 2009-09-27

"""

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)
fig.add_subplot(host)

# 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_xlabel("Time [sfm]")
host.set_ylabel("Random Data 1")
par.set_ylabel("Random Data 2")
par.axis["right"].label.set_visible(True)

p1, = host.plot(time, ydata1)
p2, = par.plot(time, ydata2)

host.axis["left"].label.set_color(p1.get_color())
par.axis["right"].label.set_color(p2.get_color())

host.axis["bottom"].label.set_size(16)
host.axis["left"].label.set_size(16)
par.axis["right"].label.set_size(16)

# 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)
title.set_position((0.5, 1.05))

plt.show()
### END CODE ###

--
Gökhan

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

JJ,

Could you please re-attach the code? Apparently, it has been forgotten on your reply.

Thanks.

···

On Sun, Sep 27, 2009 at 1:50 PM, Jae-Joon Lee <lee.j.joon@…287…> wrote:

Here is the modified version of your code that works for me.

  1. If you change trans_aux, you also need to plot your data in an

appropriate coordinate. Your original code did not work because you

scaled the xaxis of the second axes (par) but you were still plotting

the original data, i.e., “time” need to be scaled if you want to plot

it on “par”. The code below takes slightly different approach.

  1. I fount that I was wrong with the factor of 3600. It needs to be

86400, i.e., a day in seconds. Also, The unit must be larger than 1.

Again, please take a look how datetime unit works.

Regards,

-JJ

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)

fig.add_subplot(host)

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_xlabel(“Time [sfm]”)

host.set_ylabel(“Random Data 1”)

par.set_ylabel(“Random Data 2”)

par.axis[“right”].label.set_visible(True)

p1, = host.plot(time, ydata1)

p2, = par.plot(time, ydata2)

host.axis[“left”].label.set_color(p1.get_color())

par.axis[“right”].label.set_color(p2.get_color())

host.axis[“bottom”].label.set_size(16)

host.axis[“left”].label.set_size(16)

par.axis[“right”].label.set_size(16)

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)

title.set_position((0.5, 1.05))

plt.show()

On Sun, Sep 27, 2009 at 12:32 PM, Gökhan Sever <gokhansever@…287…> wrote:

Hello,

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.

BEGIN CODE

#!/usr/bin/env python

“”"

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.

Written: 2009-09-27

“”"

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)

fig.add_subplot(host)

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_xlabel(“Time [sfm]”)

host.set_ylabel(“Random Data 1”)

par.set_ylabel(“Random Data 2”)

par.axis[“right”].label.set_visible(True)

p1, = host.plot(time, ydata1)

p2, = par.plot(time, ydata2)

host.axis[“left”].label.set_color(p1.get_color())

par.axis[“right”].label.set_color(p2.get_color())

host.axis[“bottom”].label.set_size(16)

host.axis[“left”].label.set_size(16)

par.axis[“right”].label.set_size(16)

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)

title.set_position((0.5, 1.05))

plt.show()

END CODE

Gökhan


Come build with us! The BlackBerry® Developer Conference in SF, CA

is the only developer event you need to attend this year. Jumpstart your

developing skills, take BlackBerry mobile applications to market and stay

ahead of the curve. Join us from November 9-12, 2009. Register now!

http://p.sf.net/sfu/devconf


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Gökhan

Here it is.

-JJ

asdsd.py (1.55 KB)

···

On Sun, Sep 27, 2009 at 3:09 PM, Gökhan Sever <gokhansever@...287...> wrote:

JJ,

Could you please re-attach the code? Apparently, it has been forgotten on
your reply.

Thanks.

On Sun, Sep 27, 2009 at 1:50 PM, Jae-Joon Lee <lee.j.joon@...287...> wrote:

Here is the modified version of your code that works for me.

1) If you change trans_aux, you also need to plot your data in an
appropriate coordinate. Your original code did not work because you
scaled the xaxis of the second axes (par) but you were still plotting
the original data, i.e., "time" need to be scaled if you want to plot
it on "par". The code below takes slightly different approach.

2) I fount that I was wrong with the factor of 3600. It needs to be
86400, i.e., a day in seconds. Also, The unit must be larger than 1.
Again, please take a look how datetime unit works.

Regards,

-JJ

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)
fig.add_subplot(host)

# 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_xlabel("Time [sfm]")
host.set_ylabel("Random Data 1")
par.set_ylabel("Random Data 2")
par.axis["right"].label.set_visible(True)

p1, = host.plot(time, ydata1)
p2, = par.plot(time, ydata2)

host.axis["left"].label.set_color(p1.get_color())
par.axis["right"].label.set_color(p2.get_color())

host.axis["bottom"].label.set_size(16)
host.axis["left"].label.set_size(16)
par.axis["right"].label.set_size(16)

# 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)
title.set_position((0.5, 1.05))

plt.show()

On Sun, Sep 27, 2009 at 12:32 PM, Gökhan Sever <gokhansever@...985.....> >> wrote:
> Hello,
>
> 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.
>
> ### BEGIN CODE ###
> #!/usr/bin/env python
>
> """
>
> 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.
>
> Written: 2009-09-27
>
> """
>
> 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)
> fig.add_subplot(host)
>
> # 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_xlabel("Time [sfm]")
> host.set_ylabel("Random Data 1")
> par.set_ylabel("Random Data 2")
> par.axis["right"].label.set_visible(True)
>
> p1, = host.plot(time, ydata1)
> p2, = par.plot(time, ydata2)
>
> host.axis["left"].label.set_color(p1.get_color())
> par.axis["right"].label.set_color(p2.get_color())
>
> host.axis["bottom"].label.set_size(16)
> host.axis["left"].label.set_size(16)
> par.axis["right"].label.set_size(16)
>
> # 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)
> title.set_position((0.5, 1.05))
>
> plt.show()
> ### END CODE ###
>
>
> --
> Gökhan
>
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and
> stay
> ahead of the curve. Join us from November 9&#45;12, 2009. Register
> now&#33;
> http://p.sf.net/sfu/devconf
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>

--
Gökhan

When I run this as it is, and zoom once the top x-axis ticklabels disappear: http://img2.imageshack.us/img2/5493/zoom1.png

After commenting these three lines:

#locator = MinuteLocator(interval=1)
#locator = SecondLocator(interval=30)
#par2.xaxis.set_major_locator(locator)

and running I get somewhat nice view after zooms: http://img340.imageshack.us/img340/6632/zoom2.png

with a minute discrepancy; resulting with shifts on the top x-labels.

Any last thoughts?

···

On Sun, Sep 27, 2009 at 2:12 PM, Jae-Joon Lee <lee.j.joon@…287…> wrote:

Here it is.

-JJ

On Sun, Sep 27, 2009 at 3:09 PM, Gökhan Sever <gokhansever@…287…> wrote:

JJ,

Could you please re-attach the code? Apparently, it has been forgotten on

your reply.

Thanks.

On Sun, Sep 27, 2009 at 1:50 PM, Jae-Joon Lee <lee.j.joon@…287…> wrote:

Here is the modified version of your code that works for me.

  1. If you change trans_aux, you also need to plot your data in an

appropriate coordinate. Your original code did not work because you

scaled the xaxis of the second axes (par) but you were still plotting

the original data, i.e., “time” need to be scaled if you want to plot

it on “par”. The code below takes slightly different approach.

  1. I fount that I was wrong with the factor of 3600. It needs to be

86400, i.e., a day in seconds. Also, The unit must be larger than 1.

Again, please take a look how datetime unit works.

Regards,

-JJ

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)

fig.add_subplot(host)

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_xlabel(“Time [sfm]”)

host.set_ylabel(“Random Data 1”)

par.set_ylabel(“Random Data 2”)

par.axis[“right”].label.set_visible(True)

p1, = host.plot(time, ydata1)

p2, = par.plot(time, ydata2)

host.axis[“left”].label.set_color(p1.get_color())

par.axis[“right”].label.set_color(p2.get_color())

host.axis[“bottom”].label.set_size(16)

host.axis[“left”].label.set_size(16)

par.axis[“right”].label.set_size(16)

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)

title.set_position((0.5, 1.05))

plt.show()

On Sun, Sep 27, 2009 at 12:32 PM, Gökhan Sever <gokhansever@…287…> > > >> wrote:

Hello,

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.

BEGIN CODE

#!/usr/bin/env python

“”"

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.

Written: 2009-09-27

“”"

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)

fig.add_subplot(host)

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_xlabel(“Time [sfm]”)

host.set_ylabel(“Random Data 1”)

par.set_ylabel(“Random Data 2”)

par.axis[“right”].label.set_visible(True)

p1, = host.plot(time, ydata1)

p2, = par.plot(time, ydata2)

host.axis[“left”].label.set_color(p1.get_color())

par.axis[“right”].label.set_color(p2.get_color())

host.axis[“bottom”].label.set_size(16)

host.axis[“left”].label.set_size(16)

par.axis[“right”].label.set_size(16)

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)

title.set_position((0.5, 1.05))

plt.show()

END CODE

Gökhan


Come build with us! The BlackBerry® Developer Conference in SF, CA

is the only developer event you need to attend this year. Jumpstart your

developing skills, take BlackBerry mobile applications to market and

stay

ahead of the curve. Join us from November 9-12, 2009. Register

now!

http://p.sf.net/sfu/devconf


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Gökhan


Gökhan

When I run this as it is, and zoom once the top x-axis ticklabels disappear:
http://img2.imageshack.us/img2/5493/zoom1.png

After commenting these three lines:

#locator = MinuteLocator(interval=1)
#locator = SecondLocator(interval=30)
#par2.xaxis.set_major_locator(locator)

and running I get somewhat nice view after zooms:
http://img340.imageshack.us/img340/6632/zoom2.png

with a minute discrepancy; resulting with shifts on the top x-labels.

Any last thoughts?

I believe that this is due to wrong tick locations. As you easily
guess, the default tick locators are not suitable for datetime ticks
and this is why we have separate locators. Please take a look at
documentations.

http://matplotlib.sourceforge.net/api/dates_api.html

If you want to have locator that works for several zoom levels, you
may try AutoDateLocator.

from matplotlib.dates import DateFormatter, MinuteLocator,
SecondLocator, AutoDateLocator, AutoDateFormatter
locator = AutoDateLocator()
par2.xaxis.set_major_locator(locator)
formatter=AutoDateFormatter(locator)
par2.xaxis.set_major_formatter(formatter)

par2.axis["top"].major_ticklabels.set(rotation=30,
                                      ha="left",
                                      va="bottom")

While the AutoLocator seems to give too may ticks in my opinion, I
think this is as far as I can help.

Regards,

-JJ

···

On Sun, Sep 27, 2009 at 4:18 PM, Gökhan Sever <gokhansever@...287...> wrote:

On Sun, Sep 27, 2009 at 2:12 PM, Jae-Joon Lee <lee.j.joon@...287...> wrote:

Here it is.

-JJ

On Sun, Sep 27, 2009 at 3:09 PM, Gökhan Sever <gokhansever@...1896....> >> wrote:
> JJ,
>
> Could you please re-attach the code? Apparently, it has been forgotten
> on
> your reply.
>
> Thanks.
>
> On Sun, Sep 27, 2009 at 1:50 PM, Jae-Joon Lee <lee.j.joon@...287...> >> > wrote:
>>
>> Here is the modified version of your code that works for me.
>>
>> 1) If you change trans_aux, you also need to plot your data in an
>> appropriate coordinate. Your original code did not work because you
>> scaled the xaxis of the second axes (par) but you were still plotting
>> the original data, i.e., "time" need to be scaled if you want to plot
>> it on "par". The code below takes slightly different approach.
>>
>> 2) I fount that I was wrong with the factor of 3600. It needs to be
>> 86400, i.e., a day in seconds. Also, The unit must be larger than 1.
>> Again, please take a look how datetime unit works.
>>
>> Regards,
>>
>> -JJ
>>
>>
>> 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)
>> fig.add_subplot(host)
>>
>> # 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_xlabel("Time [sfm]")
>> host.set_ylabel("Random Data 1")
>> par.set_ylabel("Random Data 2")
>> par.axis["right"].label.set_visible(True)
>>
>> p1, = host.plot(time, ydata1)
>> p2, = par.plot(time, ydata2)
>>
>> host.axis["left"].label.set_color(p1.get_color())
>> par.axis["right"].label.set_color(p2.get_color())
>>
>> host.axis["bottom"].label.set_size(16)
>> host.axis["left"].label.set_size(16)
>> par.axis["right"].label.set_size(16)
>>
>> # 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)
>> title.set_position((0.5, 1.05))
>>
>> plt.show()
>>
>>
>> On Sun, Sep 27, 2009 at 12:32 PM, Gökhan Sever <gokhansever@...2015...87...> >> >> wrote:
>> > Hello,
>> >
>> > 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.
>> >
>> > ### BEGIN CODE ###
>> > #!/usr/bin/env python
>> >
>> > """
>> >
>> > 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.
>> >
>> > Written: 2009-09-27
>> >
>> > """
>> >
>> > 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)
>> > fig.add_subplot(host)
>> >
>> > # 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_xlabel("Time [sfm]")
>> > host.set_ylabel("Random Data 1")
>> > par.set_ylabel("Random Data 2")
>> > par.axis["right"].label.set_visible(True)
>> >
>> > p1, = host.plot(time, ydata1)
>> > p2, = par.plot(time, ydata2)
>> >
>> > host.axis["left"].label.set_color(p1.get_color())
>> > par.axis["right"].label.set_color(p2.get_color())
>> >
>> > host.axis["bottom"].label.set_size(16)
>> > host.axis["left"].label.set_size(16)
>> > par.axis["right"].label.set_size(16)
>> >
>> > # 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)
>> > title.set_position((0.5, 1.05))
>> >
>> > plt.show()
>> > ### END CODE ###
>> >
>> >
>> > --
>> > Gökhan
>> >
>> >
>> >
>> > ------------------------------------------------------------------------------
>> > Come build with us! The BlackBerry&reg; Developer Conference in SF,
>> > CA
>> > is the only developer event you need to attend this year. Jumpstart
>> > your
>> > developing skills, take BlackBerry mobile applications to market and
>> > stay
>> > ahead of the curve. Join us from November 9&#45;12, 2009. Register
>> > now&#33;
>> > http://p.sf.net/sfu/devconf
>> > _______________________________________________
>> > Matplotlib-users mailing list
>> > Matplotlib-users@lists.sourceforge.net
>> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>> >
>> >
>
>
>
> --
> Gökhan
>

--
Gökhan

When I run this as it is, and zoom once the top x-axis ticklabels disappear:

http://img2.imageshack.us/img2/5493/zoom1.png

After commenting these three lines:

#locator = MinuteLocator(interval=1)

#locator = SecondLocator(interval=30)

#par2.xaxis.set_major_locator(locator)

and running I get somewhat nice view after zooms:

http://img340.imageshack.us/img340/6632/zoom2.png

with a minute discrepancy; resulting with shifts on the top x-labels.

Any last thoughts?

I believe that this is due to wrong tick locations. As you easily

guess, the default tick locators are not suitable for datetime ticks

and this is why we have separate locators. Please take a look at

documentations.

http://matplotlib.sourceforge.net/api/dates_api.html

If you want to have locator that works for several zoom levels, you

may try AutoDateLocator.

from matplotlib.dates import DateFormatter, MinuteLocator,

SecondLocator, AutoDateLocator, AutoDateFormatter

locator = AutoDateLocator()
par2.xaxis.set_major_locator(locator)

formatter=AutoDateFormatter(locator)

par2.xaxis.set_major_formatter(formatter)

par2.axis[“top”].major_ticklabels.set(rotation=30,

                                  ha="left",

                                  va="bottom")

While the AutoLocator seems to give too may ticks in my opinion, I

think this is as far as I can help.

Regards,

-JJ

Yep, thanks. That gives so many ticks indeed. Would be nicer to see labels in every other tick.

This said,

locator = SecondLocator(interval=20)
par2.xaxis.set_major_locator(locator)

par2.xaxis.set_major_formatter(DateFormatter(’%H:%M:%S’))

satisfies my initial thoughts. With some pan and zoom I can achieve what I want.

Attaching the final modified file. I think this is a good demonstrative example. It is up to you further put the script into the axes_grid examples.

Thanks again for your efforts.

double_time.py (1.78 KB)

···

On Sun, Sep 27, 2009 at 7:44 PM, Jae-Joon Lee <lee.j.joon@…287…> wrote:

On Sun, Sep 27, 2009 at 4:18 PM, Gökhan Sever <gokhansever@…287…> wrote:

On Sun, Sep 27, 2009 at 2:12 PM, Jae-Joon Lee <lee.j.joon@…287…> wrote:

Here it is.

-JJ

On Sun, Sep 27, 2009 at 3:09 PM, Gökhan Sever <gokhansever@…287…> > > >> wrote:

JJ,

Could you please re-attach the code? Apparently, it has been forgotten

on

your reply.

Thanks.

On Sun, Sep 27, 2009 at 1:50 PM, Jae-Joon Lee <lee.j.joon@…287…> > > >> > wrote:

Here is the modified version of your code that works for me.

  1. If you change trans_aux, you also need to plot your data in an

appropriate coordinate. Your original code did not work because you

scaled the xaxis of the second axes (par) but you were still plotting

the original data, i.e., “time” need to be scaled if you want to plot

it on “par”. The code below takes slightly different approach.

  1. I fount that I was wrong with the factor of 3600. It needs to be

86400, i.e., a day in seconds. Also, The unit must be larger than 1.

Again, please take a look how datetime unit works.

Regards,

-JJ

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)

fig.add_subplot(host)

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_xlabel(“Time [sfm]”)

host.set_ylabel(“Random Data 1”)

par.set_ylabel(“Random Data 2”)

par.axis[“right”].label.set_visible(True)

p1, = host.plot(time, ydata1)

p2, = par.plot(time, ydata2)

host.axis[“left”].label.set_color(p1.get_color())

par.axis[“right”].label.set_color(p2.get_color())

host.axis[“bottom”].label.set_size(16)

host.axis[“left”].label.set_size(16)

par.axis[“right”].label.set_size(16)

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)

title.set_position((0.5, 1.05))

plt.show()

On Sun, Sep 27, 2009 at 12:32 PM, Gökhan Sever <gokhansever@…287…> > > >> >> wrote:

Hello,

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.

BEGIN CODE

#!/usr/bin/env python

“”"

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.

Written: 2009-09-27

“”"

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)

fig.add_subplot(host)

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_xlabel(“Time [sfm]”)

host.set_ylabel(“Random Data 1”)

par.set_ylabel(“Random Data 2”)

par.axis[“right”].label.set_visible(True)

p1, = host.plot(time, ydata1)

p2, = par.plot(time, ydata2)

host.axis[“left”].label.set_color(p1.get_color())

par.axis[“right”].label.set_color(p2.get_color())

host.axis[“bottom”].label.set_size(16)

host.axis[“left”].label.set_size(16)

par.axis[“right”].label.set_size(16)

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)

title.set_position((0.5, 1.05))

plt.show()

END CODE

Gökhan


Come build with us! The BlackBerry® Developer Conference in SF,

CA

is the only developer event you need to attend this year. Jumpstart

your

developing skills, take BlackBerry mobile applications to market and

stay

ahead of the curve. Join us from November 9-12, 2009. Register

now!

http://p.sf.net/sfu/devconf


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Gökhan

Gökhan


Gökhan

There is

When I run this as it is, and zoom once the top x-axis ticklabels disappear:

http://img2.imageshack.us/img2/5493/zoom1.png

After commenting these three lines:

#locator = MinuteLocator(interval=1)

#locator = SecondLocator(interval=30)

#par2.xaxis.set_major_locator(locator)

and running I get somewhat nice view after zooms:

http://img340.imageshack.us/img340/6632/zoom2.png

with a minute discrepancy; resulting with shifts on the top x-labels.

Any last thoughts?

I believe that this is due to wrong tick locations. As you easily

guess, the default tick locators are not suitable for datetime ticks

and this is why we have separate locators. Please take a look at

documentations.

http://matplotlib.sourceforge.net/api/dates_api.html

If you want to have locator that works for several zoom levels, you

may try AutoDateLocator.

from matplotlib.dates import DateFormatter, MinuteLocator,

SecondLocator, AutoDateLocator, AutoDateFormatter

locator = AutoDateLocator()
par2.xaxis.set_major_locator(locator)

formatter=AutoDateFormatter(locator)

par2.xaxis.set_major_formatter(formatter)

par2.axis[“top”].major_ticklabels.set(rotation=30,

                                  ha="left",

                                  va="bottom")

While the AutoLocator seems to give too may ticks in my opinion, I

think this is as far as I can help.

Regards,

-JJ

Yep, thanks. That gives so many ticks indeed. Would be nicer to see labels in every other tick.

This said,

locator = SecondLocator(interval=20)

par2.xaxis.set_major_locator(locator)

par2.xaxis.set_major_formatter(DateFormatter(’%H:%M:%S’))

satisfies my initial thoughts. With some pan and zoom I can achieve what I want.

Attaching the final modified file. I think this is a good demonstrative example. It is up to you further put the script into the axes_grid examples.

Thanks again for your efforts.

There is still issues with this approach. First and foremost it is very slow when the arrays plotted are big (in my case ~8000 points.)

AutoDateLocator() works fast, however on some zoomings the top axis is filled with labels. This needs to be addressed.

Could anyone help me to see the flow of the AutoDateLocator() class’ updates? It only behaves weird on some certain zooms, put how is this updated on the screen is a mystery to me so far. I have Eclipse + PyDev, but don’t know where should I set the breakpoints to analyse this behaviour?

Thanks.

···

On Sun, Sep 27, 2009 at 8:49 PM, Gökhan Sever <gokhansever@…287…> wrote:

On Sun, Sep 27, 2009 at 7:44 PM, Jae-Joon Lee <lee.j.joon@…287…> wrote:

On Sun, Sep 27, 2009 at 4:18 PM, Gökhan Sever <gokhansever@…287…> wrote:

On Sun, Sep 27, 2009 at 2:12 PM, Jae-Joon Lee <lee.j.joon@…287…> wrote:

Here it is.

-JJ

On Sun, Sep 27, 2009 at 3:09 PM, Gökhan Sever <gokhansever@…287…> > > > > >> wrote:

JJ,

Could you please re-attach the code? Apparently, it has been forgotten

on

your reply.

Thanks.

On Sun, Sep 27, 2009 at 1:50 PM, Jae-Joon Lee <lee.j.joon@…287…> > > > > >> > wrote:

Here is the modified version of your code that works for me.

  1. If you change trans_aux, you also need to plot your data in an

appropriate coordinate. Your original code did not work because you

scaled the xaxis of the second axes (par) but you were still plotting

the original data, i.e., “time” need to be scaled if you want to plot

it on “par”. The code below takes slightly different approach.

  1. I fount that I was wrong with the factor of 3600. It needs to be

86400, i.e., a day in seconds. Also, The unit must be larger than 1.

Again, please take a look how datetime unit works.

Regards,

-JJ

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)

fig.add_subplot(host)

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_xlabel(“Time [sfm]”)

host.set_ylabel(“Random Data 1”)

par.set_ylabel(“Random Data 2”)

par.axis[“right”].label.set_visible(True)

p1, = host.plot(time, ydata1)

p2, = par.plot(time, ydata2)

host.axis[“left”].label.set_color(p1.get_color())

par.axis[“right”].label.set_color(p2.get_color())

host.axis[“bottom”].label.set_size(16)

host.axis[“left”].label.set_size(16)

par.axis[“right”].label.set_size(16)

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)

title.set_position((0.5, 1.05))

plt.show()

On Sun, Sep 27, 2009 at 12:32 PM, Gökhan Sever <gokhansever@…1003…7…> > > > > >> >> wrote:

Hello,

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.

BEGIN CODE

#!/usr/bin/env python

“”"

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.

Written: 2009-09-27

“”"

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)

fig.add_subplot(host)

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_xlabel(“Time [sfm]”)

host.set_ylabel(“Random Data 1”)

par.set_ylabel(“Random Data 2”)

par.axis[“right”].label.set_visible(True)

p1, = host.plot(time, ydata1)

p2, = par.plot(time, ydata2)

host.axis[“left”].label.set_color(p1.get_color())

par.axis[“right”].label.set_color(p2.get_color())

host.axis[“bottom”].label.set_size(16)

host.axis[“left”].label.set_size(16)

par.axis[“right”].label.set_size(16)

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)

title.set_position((0.5, 1.05))

plt.show()

END CODE

Gökhan


Come build with us! The BlackBerry® Developer Conference in SF,

CA

is the only developer event you need to attend this year. Jumpstart

your

developing skills, take BlackBerry mobile applications to market and

stay

ahead of the curve. Join us from November 9-12, 2009. Register

now!

http://p.sf.net/sfu/devconf


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Gökhan

Gökhan


Gökhan


Gökhan