time axis format

Dear Paul,

           The issue I am facing is like in the attached plot where the month naming get cluttered.

with best regards,

Sudheer

···

Sudheer Joseph
Indian National Centre for Ocean Information Services
Ministry of Earth Sciences, Govt. of India
POST BOX NO: 21, IDA Jeedeemetla P.O.
Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55
Tel:+91-40-23886047(O),Fax:+91-40-23895011(O),
Tel:+91-40-23044600(R),Tel:+91-40-9440832534(Mobile)
E-mail:sjo.India@…287…;sudheer.joseph@…9…
Web- http://oppamthadathil.tripod.com



From: Sudheer Joseph <sudheer.joseph@…9…>
To: Paul Hobson <pmhobson@…287…>
Cc: “matplotlib-users@…431…ists.sourceforge.net” matplotlib-users@lists.sourceforge.net
Sent: Saturday, 8 June 2013 7:46 PM
Subject: Re: [Matplotlib-users] time axis format

Thank you Paul for the helping
hand,
However I was looking for slightly different solution like in the attached plots. I used ferret to do this based on the length of the time axis it chose the mode of labelling. for example in case of 2 year plot it made month labeling as j f m etc and in case of 1 year as there is enough space on x axis it made jan feb etc with single label of year.

In the attached python plot (ATser_RAMA_HYCOM_U_8n90e.png) every tick point is lablled for year, which I wanted to avoid and get plots similar to the first types thought it is not done automatically but at least
manually.


Sudheer Joseph
Indian National Centre for Ocean Information Services
Ministry of Earth Sciences, Govt. of India
POST BOX NO: 21, IDA Jeedeemetla P.O.
Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55
Tel:+91-40-23886047(O),Fax:+91-40-23895011(O),
Tel:+91-40-23044600(R),Tel:+91-40-9440832534(Mobile)
E-mail:sjo.India@…287…;sudheer.joseph@…9…
Web- http://oppamthadathil.tripod.com



From: Paul Hobson <pmhobson@…287…>
To: Sudheer Joseph <sudheer.joseph@…9…>
Cc: “matplotlib-users@…564…net” matplotlib-users@lists.sourceforge.net
Sent: Friday, 7 June 2013 8:50 PM
Subject: Re: [Matplotlib-users] time axis format

On Thu, Jun 6, 2013 at 11:39 PM, Sudheer Joseph <sudheer.joseph@…9…> wrote:

Dear Experts,

        I have been experimenting with the plot_dates option of matplotlib to plot time series data and have below questions

I have used

loc = mdates.AutoDateLocator()

ax.xaxis.set_major_locator(loc)

ax.xaxis.set_major_formatter(mpl.dates.DateFormatter(‘%b\n %Y’))

and got the tick labels in attached plot

However I feel the repeatd year labeling is not needed here and it is required once in a year only , Also if I need to plot long time seris insted of “MAR” “APR” I wanted to get them reduced to “M” “A” etc so that the lavel congestion can be avoided.

I notice that below options are available, but was wondering how commbinatins of these locateors are used ie mark every month and every year once each.

Is there a way to achive the above or does it need further development?

fmt = mdates.DateFormatter(‘%Y-%m-%d’)

loc = mdates.WeekdayLocator(byweekday=mdates.MONDAY,interval=4)

locator = mdates.YearLocator()

If I were trying to do this, I’d cobble something together using by the minor and major formatters.

e.g.,…

import matplotlib.dates as mdates

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

majorLocs = mdates.MonthLocator(bymonth[1,7])

majorFmt = mdates.DateFormatter(‘%b\n%Y’)

minorLocs = mdates.MonthLocator(bymonth[1,7])

minorFmt = mdates.DateFormatter(‘%b’)

ax.xaxis.set_major_locator(majorLocs)

ax.xaxis.set_major_formatter(majorFmt)

ax.xaxis.set_minor_locator(minorLocs)

ax.xaxis.set_minor_formatter(minorFmt)

In that case, I would use ax.tick_params(…) to make the font smaller.

···

On Sat, Jun 8, 2013 at 7:36 AM, Sudheer Joseph <sudheer.joseph@…9…> wrote:

Dear Paul,

           The issue I am facing is like in the attached plot where the month naming get cluttered.

with best regards,

Sudheer


Sudheer Joseph
Indian National Centre for Ocean Information Services
Ministry of Earth Sciences, Govt. of India

POST BOX NO: 21, IDA Jeedeemetla P.O.
Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55
Tel:+91-40-23886047(O),Fax:+91-40-23895011(O),

Tel:+91-40-23044600(R),Tel:+91-40-9440832534(Mobile)
E-mail:sjo.India@…1972…;sudheer.joseph@…9…

Web- http://oppamthadathil.tripod.com



From: Sudheer Joseph <sudheer.joseph@…9…>
To: Paul Hobson <pmhobson@…287…>
Cc:matplotlib-users@lists.sourceforge.net” <matplotlib-users@…2982…e.net>
Sent: Saturday, 8 June 2013 7:46 PM

Subject: Re: [Matplotlib-users] time axis format

Thank you Paul for the helping
hand,
However I was looking for slightly different solution like in the attached plots. I used ferret to do this based on the length of the time axis it chose the mode of labelling. for example in case of 2 year plot it made month labeling as j f m etc and in case of 1 year as there is enough space on x axis it made jan feb etc with single label of year.

In the attached python plot (ATser_RAMA_HYCOM_U_8n90e.png) every tick point is lablled for year, which I wanted to avoid and get plots similar to the first types thought it is not done automatically but at least
manually.


Sudheer Joseph
Indian National Centre for Ocean Information Services
Ministry of Earth Sciences, Govt. of India

POST BOX NO: 21, IDA Jeedeemetla P.O.
Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55
Tel:+91-40-23886047(O),Fax:+91-40-23895011(O),

Tel:+91-40-23044600(R),Tel:+91-40-9440832534(Mobile)
E-mail:sjo.India@…1972…;sudheer.joseph@…9…

Web- http://oppamthadathil.tripod.com



From: Paul Hobson <pmhobson@…287…>
To: Sudheer Joseph <sudheer.joseph@…1762…>
Cc:matplotlib-users@lists.sourceforge.net” <matplotlib-users@…2569…sourceforge.net>
Sent: Friday, 7 June 2013 8:50 PM
Subject: Re: [Matplotlib-users] time axis format

On Thu, Jun 6, 2013 at 11:39 PM, Sudheer Joseph <sudheer.joseph@…9…> wrote:

Dear Experts,

        I have been experimenting with the plot_dates option of matplotlib to plot time series data and have below questions

I have used

loc = mdates.AutoDateLocator()

ax.xaxis.set_major_locator(loc)

ax.xaxis.set_major_formatter(mpl.dates.DateFormatter(‘%b\n %Y’))

and got the tick labels in attached plot

However I feel the repeatd year labeling is not needed here and it is required once in a year only , Also if I need to plot long time seris insted of “MAR” “APR” I wanted to get them reduced to “M” “A” etc so that the lavel congestion can be avoided.

I notice that below options are available, but was wondering how commbinatins of these locateors are used ie mark every month and every year once each.

Is there a way to achive the above or does it need further development?

fmt = mdates.DateFormatter(‘%Y-%m-%d’)

loc = mdates.WeekdayLocator(byweekday=mdates.MONDAY,interval=4)

locator = mdates.YearLocator()

If I were trying to do this, I’d cobble something together using by the minor and major formatters.

e.g.,…

import matplotlib.dates as mdates

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

majorLocs = mdates.MonthLocator(bymonth[1,7])

majorFmt = mdates.DateFormatter(‘%b\n%Y’)

minorLocs = mdates.MonthLocator(bymonth[1,7])

minorFmt = mdates.DateFormatter(‘%b’)

ax.xaxis.set_major_locator(majorLocs)

ax.xaxis.set_major_formatter(majorFmt)

ax.xaxis.set_minor_locator(minorLocs)

ax.xaxis.set_minor_formatter(minorFmt)

Thank you,
So there is no way to get J F M A etc with out reducing font size? We often need to make presentation in front of senior people who insist for bigger fonts.
With best regards,
Sudheer

···

On Sat, Jun 8, 2013 at 7:36 AM, Sudheer Joseph <sudheer.joseph@…9…> wrote:

Dear Paul,

           The issue I am facing is like in the attached plot where the month naming get cluttered.

with best regards,

Sudheer


Sudheer Joseph
Indian National Centre for Ocean Information Services
Ministry of Earth Sciences, Govt. of India

POST BOX NO: 21, IDA Jeedeemetla P.O.
Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55
Tel:+91-40-23886047(O),Fax:+91-40-23895011(O),

Tel:+91-40-23044600(R),Tel:+91-40-9440832534(Mobile)
E-mail:sjo.India@…287…;sudheer.joseph@…9…

Web- http://oppamthadathil.tripod.com



From: Sudheer Joseph <sudheer.joseph@…9…>
To: Paul Hobson <pmhobson@…287…>
Cc:matplotlib-users@lists.sourceforge.netmatplotlib-users@lists.sourceforge.net
Sent: Saturday, 8 June 2013 7:46 PM

Subject: Re: [Matplotlib-users] time axis format

Thank you Paul for the helping
hand,
However I was looking for slightly different solution like in the attached plots. I used ferret to do this based on the length of the time axis it chose the mode of labelling. for example in case of 2 year plot it made month labeling as j f m etc and in case of 1 year as there is enough space on x axis it made jan feb etc with single label of year.

In the attached python plot (ATser_RAMA_HYCOM_U_8n90e.png) every tick point is lablled for year, which I wanted to avoid and get plots similar to the first types thought it is not done automatically but at least
manually.


Sudheer Joseph
Indian National Centre for Ocean Information Services
Ministry of Earth Sciences, Govt. of India

POST BOX NO: 21, IDA Jeedeemetla P.O.
Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55
Tel:+91-40-23886047(O),Fax:+91-40-23895011(O),

Tel:+91-40-23044600(R),Tel:+91-40-9440832534(Mobile)
E-mail:sjo.India@…287…;sudheer.joseph@…9…

Web- http://oppamthadathil.tripod.com



From: Paul Hobson <pmhobson@…287…>
To: Sudheer Joseph <sudheer.joseph@…9…>
Cc:matplotlib-users@lists.sourceforge.net” <matplotlib-users@…2018…rceforge.net>
Sent: Friday, 7 June 2013 8:50 PM
Subject: Re: [Matplotlib-users] time axis format

On Thu, Jun 6, 2013 at 11:39 PM, Sudheer Joseph <sudheer.joseph@…9…> wrote:

Dear Experts,

        I have been experimenting with the plot_dates option of matplotlib to plot time series data and have below questions

I have used

loc = mdates.AutoDateLocator()

ax.xaxis.set_major_locator(loc)

ax.xaxis.set_major_formatter(mpl.dates.DateFormatter(‘%b\n %Y’))

and got the tick labels in attached plot

However I feel the repeatd year labeling is not needed here and it is required once in a year only , Also if I need to plot long time seris insted of “MAR” “APR” I wanted to get them reduced to “M” “A” etc so that the lavel congestion can be avoided.

I notice that below options are available, but was wondering how commbinatins of these locateors are used ie mark every month and every year once each.

Is there a way to achive the above or does it need further development?

fmt = mdates.DateFormatter(‘%Y-%m-%d’)

loc = mdates.WeekdayLocator(byweekday=mdates.MONDAY,interval=4)

locator = mdates.YearLocator()

If I were trying to do this, I’d cobble something together using by the minor and major formatters.

e.g.,…

import matplotlib.dates as mdates

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

majorLocs = mdates.MonthLocator(bymonth[1,7])

majorFmt = mdates.DateFormatter(‘%b\n%Y’)

minorLocs = mdates.MonthLocator(bymonth[1,7])

minorFmt = mdates.DateFormatter(‘%b’)

ax.xaxis.set_major_locator(majorLocs)

ax.xaxis.set_major_formatter(majorFmt)

ax.xaxis.set_minor_locator(minorLocs)

ax.xaxis.set_minor_formatter(minorFmt)

Thank you,
So there is no way to get J F M A etc with out reducing font size? We
often need to make presentation in front of senior people who insist for
bigger fonts.
With best regards,
Sudheer

One way is to subclass DateFormatter, e.g.,

class MonthLetter(DateFormatter):
     def __init__(self):
         DateFormatter.__init__(self, "%b")

     def __call__(*args):
         s = DateFormatter.__call__(*args)
         return s[:1]

class MonthLetterYear(DateFormatter):
     def __init__(self):
         DateFormatter.__init__(self, "%b\n%Y")

     def __call__(*args):
         s = DateFormatter.__call__(*args)
         return = s[:1] + s[3:]

...

majorFmt = MonthLetterYear()
minorFmt = MonthLetter()

Not tested, but something like that should work.

Eric

···

On 2013/06/10 2:08 PM, Sudheer Joseph wrote:

------------------------------------------------------------------------
*From: * Paul Hobson <pmhobson@...287...>;
*To: * Sudheer Joseph <sudheer.joseph@...9...>;
*Cc: * matplotlib-users@lists.sourceforge.net
<matplotlib-users@lists.sourceforge.net>;
*Subject: * Re: [Matplotlib-users] time axis format
*Sent: * Mon, Jun 10, 2013 8:08:18 PM

In that case, I would use ax.tick_params(...) to make the font smaller.

On Sat, Jun 8, 2013 at 7:36 AM, Sudheer Joseph <sudheer.joseph@...9... > <javascript:return>> wrote:

    Dear Paul,
                    The issue I am facing is like in the attached plot
    where the month naming get cluttered.
    with best regards,
    Sudheer
    ***************************************************************
    Sudheer Joseph
    Indian National Centre for Ocean Information Services
    Ministry of Earth Sciences, Govt. of India
    POST BOX NO: 21, IDA Jeedeemetla P.O.
    Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55
    Tel:+91-40-23886047(O),Fax:+91-40-23895011(O),
    Tel:+91-40-23044600(R),Tel:+91-40-9440832534(Mobile)
    E-mail:sjo.India@...287...
    <javascript:return>;sudheer.joseph@...9... <javascript:return>
    Web- http://oppamthadathil.tripod.com
    ***************************************************************

        ------------------------------------------------------------------------
        *From:* Sudheer Joseph <sudheer.joseph@...9...
        <javascript:return>>
        *To:* Paul Hobson <pmhobson@...287... <javascript:return>>
        *Cc:* "matplotlib-users@lists.sourceforge.net
        <javascript:return>" <matplotlib-users@lists.sourceforge.net
        <javascript:return>>
        *Sent:* Saturday, 8 June 2013 7:46 PM

        *Subject:* Re: [Matplotlib-users] time axis format

        Thank you Paul for the helping hand,
                                           However I was looking for
        slightly different solution like in the attached plots. I used
        ferret to do this based on the length of the time axis it chose
        the mode of labelling. for example in case of 2 year plot it
        made month labeling as j f m etc and in case of 1 year as there
        is enough space on x axis it made jan feb etc with single label
        of year.

        In the attached python plot (ATser_RAMA_HYCOM_U_8n90e.png) every
        tick point is lablled for year, which I wanted to avoid and get
        plots similar to the first types thought it is not done
        automatically but at least manually.

        ***************************************************************
        Sudheer Joseph
        Indian National Centre for Ocean Information Services
        Ministry of Earth Sciences, Govt. of India
        POST BOX NO: 21, IDA Jeedeemetla P.O.
        Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55
        Tel:+91-40-23886047(O),Fax:+91-40-23895011(O),
        Tel:+91-40-23044600(R),Tel:+91-40-9440832534(Mobile)
        E-mail:sjo.India@...287...
        <javascript:return>;sudheer.joseph@...9... <javascript:return>
        Web- http://oppamthadathil.tripod.com
        ***************************************************************

            ------------------------------------------------------------------------
            *From:* Paul Hobson <pmhobson@...287... <javascript:return>>
            *To:* Sudheer Joseph <sudheer.joseph@...9...
            <javascript:return>>
            *Cc:* "matplotlib-users@lists.sourceforge.net
            <javascript:return>" <matplotlib-users@lists.sourceforge.net
            <javascript:return>>
            *Sent:* Friday, 7 June 2013 8:50 PM
            *Subject:* Re: [Matplotlib-users] time axis format

            On Thu, Jun 6, 2013 at 11:39 PM, Sudheer Joseph > <sudheer.joseph@...9... <javascript:return>> wrote:

                Dear Experts,
                             I have been experimenting with the
                plot_dates option of matplotlib to plot time series data
                and have below questions

                  I have used
                loc = mdates.AutoDateLocator()
                ax.xaxis.set_major_locator(loc)
                ax.xaxis.set_major_formatter(mpl.dates.DateFormatter('%b\n
                %Y'))

                and got the tick labels in attached plot

                However I feel the repeatd year labeling is not needed
                here and it is required once in a year only , Also if I
                need to plot long time seris insted of "MAR" "APR" I
                wanted to get them reduced to "M" "A" etc so that the
                lavel congestion can be avoided.

                I notice that below options are available, but was
                wondering how commbinatins of these locateors are used
                ie mark every month and every year once each.

                Is there a way to achive the above or does it need
                further development?

                fmt = mdates.DateFormatter('%Y-%m-%d')
                loc =
                mdates.WeekdayLocator(byweekday=mdates.MONDAY,interval=4)
                locator = mdates.YearLocator()

            If I were trying to do this, I'd cobble something together
            using by the minor and major formatters.
            e.g.,...
            import matplotlib.dates as mdates
            import matplotlib.pyplot as plt

            fig, ax = plt.subplots()

            majorLocs = mdates.MonthLocator(bymonth[1,7])
            majorFmt = mdates.DateFormatter('%b\n%Y')

            minorLocs = mdates.MonthLocator(bymonth[1,7])
            minorFmt = mdates.DateFormatter('%b')

            ax.xaxis.set_major_locator(majorLocs)
            ax.xaxis.set_major_formatter(majorFmt)

            ax.xaxis.set_minor_locator(minorLocs)
            ax.xaxis.set_minor_formatter(minorFmt)

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Thank you,
So there is no way to get J F M A etc with out reducing font size?

I bet there a number of ways. Offhand I don’t know the one that, once I hear about it, I will say, “D’oh, that’s so easy” but I bet it exists. But you could modify the DateFormatter class. It is set to return a strftime result string. Here is the function:

def call(self, x, pos=0):
if x==0:
raise ValueError(‘DateFormatter found a value of x=0, which is an illegal date. This usually occurs because you have not informed the axis that it is plotting dates, eg with ax.xaxis_date()’)

    dt = num2date(x, [self.tz](http://self.tz))
    return self.strftime(dt, self.fmt)

All you would have to do is change that last line to:

    return self.strftime(dt, self.fmt)[0]

To slice just the first letter of the month.

So you could subclass DateFormatter to do this, since you probably don’t want to modify the actual DateFormatter class always in this way.

Also, aside from the J F M A approach, you could just rotate the month’s name, and that will reduce crowding while keeping the month a little clearer (I think “JAN FEB MAR APR” is more intuitive and pleasant to read on a graph).

Che

···

On Sat, Jun 8, 2013 at 7:36 AM, Sudheer Joseph <sudheer.joseph@…9…> wrote:

Dear Paul,

           The issue I am facing is like in the attached plot where the month naming get cluttered.

with best regards,

Sudheer


Sudheer Joseph
Indian National Centre for Ocean Information Services
Ministry of Earth Sciences, Govt. of India

POST BOX NO: 21, IDA Jeedeemetla P.O.
Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55
Tel:+91-40-23886047(O),Fax:+91-40-23895011(O),

Tel:+91-40-23044600(R),Tel:+91-40-9440832534(Mobile)
E-mail:sjo.India@…287…;sudheer.joseph@…9…

Web- http://oppamthadathil.tripod.com



From: Sudheer Joseph <sudheer.joseph@…9…>
To: Paul Hobson <pmhobson@…287…>
Cc: “matplotlib-users@…563…eforge.net” <matplotlib-users@…712…orge.net>
Sent: Saturday, 8 June 2013 7:46 PM

Subject: Re: [Matplotlib-users] time axis format

Thank you Paul for the helping
hand,
However I was looking for slightly different solution like in the attached plots. I used ferret to do this based on the length of the time axis it chose the mode of labelling. for example in case of 2 year plot it made month labeling as j f m etc and in case of 1 year as there is enough space on x axis it made jan feb etc with single label of year.

In the attached python plot (ATser_RAMA_HYCOM_U_8n90e.png) every tick point is lablled for year, which I wanted to avoid and get plots similar to the first types thought it is not done automatically but at least
manually.


Sudheer Joseph
Indian National Centre for Ocean Information Services
Ministry of Earth Sciences, Govt. of India

POST BOX NO: 21, IDA Jeedeemetla P.O.
Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55
Tel:+91-40-23886047(O),Fax:+91-40-23895011(O),

Tel:+91-40-23044600(R),Tel:+91-40-9440832534(Mobile)
E-mail:sjo.India@…287…;sudheer.joseph@…9…

Web- http://oppamthadathil.tripod.com



From: Paul Hobson <pmhobson@…287…>
To: Sudheer Joseph <sudheer.joseph@…9…>
Cc: “matplotlib-users@…2569…sourceforge.net” <matplotlib-users@…813…ourceforge.net>
Sent: Friday, 7 June 2013 8:50 PM
Subject: Re: [Matplotlib-users] time axis format

On Thu, Jun 6, 2013 at 11:39 PM, Sudheer Joseph <sudheer.joseph@…9…> wrote:

Dear Experts,

        I have been experimenting with the plot_dates option of matplotlib to plot time series data and have below questions

I have used

loc = mdates.AutoDateLocator()

ax.xaxis.set_major_locator(loc)

ax.xaxis.set_major_formatter(mpl.dates.DateFormatter(‘%b\n %Y’))

and got the tick labels in attached plot

However I feel the repeatd year labeling is not needed here and it is required once in a year only , Also if I need to plot long time seris insted of “MAR” “APR” I wanted to get them reduced to “M” “A” etc so that the lavel congestion can be avoided.

I notice that below options are available, but was wondering how commbinatins of these locateors are used ie mark every month and every year once each.

Is there a way to achive the above or does it need further development?

fmt = mdates.DateFormatter(‘%Y-%m-%d’)

loc = mdates.WeekdayLocator(byweekday=mdates.MONDAY,interval=4)

locator = mdates.YearLocator()

If I were trying to do this, I’d cobble something together using by the minor and major formatters.

e.g.,…

import matplotlib.dates as mdates

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

majorLocs = mdates.MonthLocator(bymonth[1,7])

majorFmt = mdates.DateFormatter(‘%b\n%Y’)

minorLocs = mdates.MonthLocator(bymonth[1,7])

minorFmt = mdates.DateFormatter(‘%b’)

ax.xaxis.set_major_locator(majorLocs)

ax.xaxis.set_major_formatter(majorFmt)

ax.xaxis.set_minor_locator(minorLocs)

ax.xaxis.set_minor_formatter(minorFmt)

Thank you Eric and CM,
I have the below piece of code and added the new definition for minorLocs, but gets the below error. I believe I did not fully understand the concept you mentioned.

minorLocs = mdates.MonthLocator(bymonth=[1,3,5,7,9,11],bymonthday=15)
minorFmt = mdates.DateFormatter('%b')

class MonthLetter(minorFmt):
def __init__(self):
DateFormatter.__init__(self, "%b")
def __call__(*args):
s = DateFormatter.__call__(*args)
return s[:1]
minorFmt = MonthLetter()

531     def viewlim\_to\_dt\(self\):

--> 532 vmin, vmax = self.axis.get_view_interval()
533 return num2date(vmin, self.tz), num2date(vmax, self.tz)
534

AttributeError: 'NoneType' object has no attribute 'get_view_interva

···

From: Eric Firing <efiring@...202...>

To: matplotlib-users@lists.sourceforge.net

Sent: Tuesday, 11 June 2013 6:11 AM
Subject: Re: [Matplotlib-users] time axis format

On 2013/06/10 2:08 PM, Sudheer Joseph wrote:

Thank you,
So there is no way to get J F M A etc with out reducing font size? We
often need to make presentation in front of senior people who insist for
bigger fonts.
With best regards,
Sudheer

One way is to subclass DateFormatter, e.g.,

class MonthLetter(DateFormatter):
def __init__(self):
DateFormatter.__init__(self, "%b")

 def \_\_call\_\_\(\*args\):
     s = DateFormatter\.\_\_call\_\_\(\*args\)
     return s\[:1\]

class MonthLetterYear(DateFormatter):
def __init__(self):
DateFormatter.__init__(self, "%b\n%Y")

 def \_\_call\_\_\(\*args\):
     s = DateFormatter\.\_\_call\_\_\(\*args\)
     return = s\[:1\] \+ s\[3:\]

...

majorFmt = MonthLetterYear()
minorFmt = MonthLetter()

Not tested, but something like that should work.

Eric

------------------------------------------------------------------------
*From: * Paul Hobson <pmhobson@...287...>;
*To: * Sudheer Joseph <sudheer.joseph@...9...>;
*Cc: * matplotlib-users@lists.sourceforge.net
<matplotlib-users@lists.sourceforge.net>;
*Subject: * Re: [Matplotlib-users] time axis format
*Sent: * Mon, Jun 10, 2013 8:08:18 PM

In that case, I would use ax.tick_params(...) to make the font smaller.

On Sat, Jun 8, 2013 at 7:36 AM, Sudheer Joseph <sudheer.joseph@...9... >> <javascript:return>> wrote:

 Dear Paul,
                 The issue I am facing is like in the attached plot
 where the month naming get cluttered\.
 with best regards,
 Sudheer
 \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
 Sudheer Joseph
 Indian National Centre for Ocean Information Services
 Ministry of Earth Sciences, Govt\. of India
 POST BOX NO: 21, IDA Jeedeemetla P\.O\.
 Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55
 Tel:\+91\-40\-23886047\(O\),Fax:\+91\-40\-23895011\(O\),
 Tel:\+91\-40\-23044600\(R\),Tel:\+91\-40\-9440832534\(Mobile\)
 E\-mail:sjo\.India@\.\.\.287\.\.\.
 &lt;javascript:return&gt;;sudheer\.joseph@\.\.\.9\.\.\. &lt;javascript:return&gt;
 Web\- http://oppamthadathil.tripod.com
 \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

     \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
     \*From:\* Sudheer Joseph &lt;sudheer\.joseph@\.\.\.9\.\.\.
     &lt;javascript:return&gt;&gt;
     \*To:\* Paul Hobson &lt;pmhobson@\.\.\.287\.\.\. &lt;javascript:return&gt;&gt;
     \*Cc:\* &quot;matplotlib\-users@lists\.sourceforge\.net
     &lt;javascript:return&gt;&quot; &lt;matplotlib\-users@\.\.\.712\.\.\.orge\.net
     &lt;javascript:return&gt;&gt;
     \*Sent:\* Saturday, 8 June 2013 7:46 PM

     \*Subject:\* Re: \[Matplotlib\-users\] time axis format

     Thank you Paul for the helping hand,
                                        However I was looking for
     slightly different solution like in the attached plots\. I used
     ferret to do this based on the length of the time axis it chose
     the mode of labelling\. for example in case of 2 year plot it
     made month labeling as j f m etc and in case of 1 year as there
     is enough space on x axis it made jan feb etc with single label
     of year\.

     In the attached python plot \(ATser\_RAMA\_HYCOM\_U\_8n90e\.png\) every
     tick point is lablled for year, which I wanted to avoid and get
     plots similar to the first types thought it is not done
     automatically but at least manually\.

     \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
     Sudheer Joseph
     Indian National Centre for Ocean Information Services
     Ministry of Earth Sciences, Govt\. of India
     POST BOX NO: 21, IDA Jeedeemetla P\.O\.
     Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55
     Tel:\+91\-40\-23886047\(O\),Fax:\+91\-40\-23895011\(O\),
     Tel:\+91\-40\-23044600\(R\),Tel:\+91\-40\-9440832534\(Mobile\)
     E\-mail:sjo\.India@\.\.\.287\.\.\.
     &lt;javascript:return&gt;;sudheer\.joseph@\.\.\.9\.\.\. &lt;javascript:return&gt;
     Web\- http://oppamthadathil.tripod.com
     \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

         \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
         \*From:\* Paul Hobson &lt;pmhobson@\.\.\.287\.\.\. &lt;javascript:return&gt;&gt;
         \*To:\* Sudheer Joseph &lt;sudheer\.joseph@\.\.\.9\.\.\.
         &lt;javascript:return&gt;&gt;
         \*Cc:\* &quot;matplotlib\-users@lists\.sourceforge\.net
         &lt;javascript:return&gt;&quot; &lt;matplotlib\-users@\.\.\.2569\.\.\.\.sourceforge\.net
         &lt;javascript:return&gt;&gt;
         \*Sent:\* Friday, 7 June 2013 8:50 PM
         \*Subject:\* Re: \[Matplotlib\-users\] time axis format

         On Thu, Jun 6, 2013 at 11:39 PM, Sudheer Joseph &gt;&gt;             &lt;sudheer\.joseph@\.\.\.9\.\.\. &lt;javascript:return&gt;&gt; wrote:

             Dear Experts,
                          I have been experimenting with the
             plot\_dates option of matplotlib to plot time series data
             and have below questions

               I have used
             loc = mdates\.AutoDateLocator\(\)
             ax\.xaxis\.set\_major\_locator\(loc\)
             ax\.xaxis\.set\_major\_formatter\(mpl\.dates\.DateFormatter\(&#39;%b\\n
             %Y&#39;\)\)

             and got the tick labels in attached plot

             However I feel the repeatd year labeling is not needed
             here and it is required once in a year only , Also if I
             need to plot long time seris insted of &quot;MAR&quot; &quot;APR&quot; I
             wanted to get them reduced to &quot;M&quot; &quot;A&quot; etc so that the
             lavel congestion can be avoided\.

             I notice that below options are available, but was
             wondering how commbinatins of these locateors are used
             ie mark every month and every year once each\.

             Is there a way to achive the above or does it need
             further development?

             fmt = mdates\.DateFormatter\(&#39;%Y\-%m\-%d&#39;\)
             loc =
             mdates\.WeekdayLocator\(byweekday=mdates\.MONDAY,interval=4\)
             locator = mdates\.YearLocator\(\)

         If I were trying to do this, I&#39;d cobble something together
         using by the minor and major formatters\.
         e\.g\.,\.\.\.
         import matplotlib\.dates as mdates
         import matplotlib\.pyplot as plt

         fig, ax = plt\.subplots\(\)

         majorLocs = mdates\.MonthLocator\(bymonth\[1,7\]\)
         majorFmt = mdates\.DateFormatter\(&#39;%b\\n%Y&#39;\)

         minorLocs = mdates\.MonthLocator\(bymonth\[1,7\]\)
         minorFmt = mdates\.DateFormatter\(&#39;%b&#39;\)

         ax\.xaxis\.set\_major\_locator\(majorLocs\)
         ax\.xaxis\.set\_major\_formatter\(majorFmt\)

         ax\.xaxis\.set\_minor\_locator\(minorLocs\)
         ax\.xaxis\.set\_minor\_formatter\(minorFmt\)

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Thank you CM,
I tried to rotate the labels but only major ticks get rotated and when I try with minor ticks as below I get error

minlabels = ax.xaxis.get_minor_ticks()
p.xticks(minlabels,rotation=90)

--> 192 base = float(dt.toordinal())
193 if hasattr(dt, 'hour'):
194 base += (dt.hour/HOURS_PER_DAY + dt.minute/MINUTES_PER_DAY +

AttributeError: 'XTick' object has no attribute 'toordinal'

Sent: Tuesday, 11 June 2013 6:41 AM
Subject: Re: [Matplotlib-users] time axis format

Thank you,
So there is no way to get J F M A etc with out reducing font size?

I bet there a number of ways. Offhand I don't know the one that, once I hear about it, I will say, "D'oh, that's so easy" but I bet it exists. But you could modify the DateFormatter class. It is set to return a strftime result string. Here is the function:

def __call__(self, x, pos=0):
if x==0:
raise ValueError('DateFormatter found a value of x=0, which is an illegal date. This usually occurs because you have not informed the axis that it is plotting dates, eg with ax.xaxis_date()')
dt = num2date(x, self.tz)
return self.strftime(dt, self.fmt)

All you would have to do is change that last line to:

    return self\.strftime\(dt, self\.fmt\)\[0\]

To slice just the first letter of the month.

So you could subclass DateFormatter to do this, since you probably don't want to modify the actual DateFormatter class always in this way.

Also, aside from the J F M A approach, you could just rotate the month's name, and that will reduce crowding while keeping the month a little clearer (I think "JAN FEB MAR APR" is more intuitive and pleasant to read on a graph).

Che

We often need to make presentation in front of senior people who insist for bigger fonts.

With best regards,
Sudheer

________________________________
From: Paul Hobson <pmhobson@...287...>;
To: Sudheer Joseph <sudheer.joseph@...9...>;
Cc: matplotlib-users@lists.sourceforge.net <matplotlib-users@...813...ourceforge.net>;

Subject: Re: [Matplotlib-users] time axis format
Sent: Mon, Jun 10, 2013 8:08:18 PM

In that case, I would use ax.tick_params(...) to make the font smaller.

Dear Paul,

           The issue I am facing is like in the attached plot where the month naming get cluttered\.

with best regards,
Sudheer

***************************************************************
Sudheer Joseph
Indian National Centre for Ocean Information Services
Ministry of Earth Sciences, Govt. of India
POST BOX NO: 21, IDA Jeedeemetla P.O.
Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55
Tel:+91-40-23886047(O),Fax:+91-40-23895011(O),
Tel:+91-40-23044600(R),Tel:+91-40-9440832534(Mobile)
E-mail:sjo.India@...287...;sudheer.joseph@...9...
Web- http://oppamthadathil.tripod.com
***************************************************************

________________________________
From: Sudheer Joseph <sudheer.joseph@...9...>
To: Paul Hobson <pmhobson@...287...>
Cc: "matplotlib-users@lists.sourceforge.net" <matplotlib-users@...1838...urceforge.net>
Sent: Saturday, 8 June 2013 7:46 PM

Subject: Re: [Matplotlib-users] time axis format

Thank you Paul for the helping hand,
However I was looking for slightly different solution like in the attached plots. I used ferret to do this based on the length of the time axis it chose the mode of labelling. for example in case of 2 year plot it made month labeling as j f m etc and in case of 1 year as there is enough space on x axis it made jan feb etc with single label of year.

In the attached python plot (ATser_RAMA_HYCOM_U_8n90e.png) every tick point is lablled for year, which I wanted to avoid and get plots similar to the first types thought it is not done automatically but at least

manually.

···

From: C M <cmpython@...287...>
To: matplotlib-users@lists.sourceforge.net

On Mon, Jun 10, 2013 at 8:08 PM, Sudheer Joseph <sudheer.joseph@...9...> wrote:

On Sat, Jun 8, 2013 at 7:36 AM, Sudheer Joseph <sudheer.joseph@...9...> wrote:

***************************************************************
Sudheer Joseph
Indian National Centre for Ocean Information Services
Ministry of Earth Sciences, Govt. of India
POST BOX NO: 21, IDA Jeedeemetla P.O.
Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55
Tel:+91-40-23886047(O),Fax:+91-40-23895011(O),
Tel:+91-40-23044600(R),Tel:+91-40-9440832534(Mobile)
E-mail:sjo.India@...287...;sudheer.joseph@...9...
Web- http://oppamthadathil.tripod.com
***************************************************************

________________________________
From: Paul Hobson <pmhobson@...287...>
To: Sudheer Joseph <sudheer.joseph@...9...>
Cc: "matplotlib-users@lists.sourceforge.net" <matplotlib-users@...813...ourceforge.net>
Sent: Friday, 7 June 2013 8:50 PM
Subject: Re: [Matplotlib-users] time axis format

On Thu, Jun 6, 2013 at 11:39 PM, Sudheer Joseph <sudheer.joseph@...2652....> wrote:

Dear Experts,

        I have been experimenting with the plot\_dates option of matplotlib to plot time series data and have below questions

I have used
loc = mdates.AutoDateLocator()
ax.xaxis.set_major_locator(loc)
ax.xaxis.set_major_formatter(mpl.dates.DateFormatter('%b\n %Y'))

and got the tick labels in attached plot

However I feel the repeatd year labeling is not needed here and it is required once in a year only , Also if I need to plot long time seris insted of "MAR" "APR" I wanted to get them reduced to "M" "A" etc so that the lavel congestion can be avoided.

I notice that below options are available, but was wondering how commbinatins of these locateors are used ie mark every month and every year once each.

Is there a way to achive the above or does it need further development?

fmt = mdates.DateFormatter('%Y-%m-%d')
loc = mdates.WeekdayLocator(byweekday=mdates.MONDAY,interval=4)
locator = mdates.YearLocator()

If I were trying to do this, I'd cobble something together using by the minor and major formatters.
e.g.,...
import matplotlib.dates as mdates
import matplotlib.pyplot as plt

fig, ax = plt.subplots()

majorLocs = mdates.MonthLocator(bymonth[1,7])
majorFmt = mdates.DateFormatter('%b\n%Y')

minorLocs = mdates.MonthLocator(bymonth[1,7])
minorFmt = mdates.DateFormatter('%b')

ax.xaxis.set_major_locator(majorLocs)
ax.xaxis.set_major_formatter(majorFmt)

ax.xaxis.set_minor_locator(minorLocs)
ax.xaxis.set_minor_formatter(minorFmt)

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Got a solution as below

p.setp(ax.xaxis.get_minorticklabels(), rotation=90 )
but still to understand how to get single letter from month name!

with best regards,
Sudheer

···

----- Original Message -----

From: Sudheer Joseph <sudheer.joseph@...9...>
To: Eric Firing <efiring@...202...>; "matplotlib-users@...564...net" <matplotlib-users@lists.sourceforge.net>
Cc:
Sent: Tuesday, 11 June 2013 9:46 AM
Subject: Re: [Matplotlib-users] time axis format

Thank you Eric and CM,
I have the below piece of code and added the new definition for minorLocs, but
gets the below error. I believe I did not fully understand the concept you
mentioned.

minorLocs = mdates.MonthLocator(bymonth=[1,3,5,7,9,11],bymonthday=15)
minorFmt = mdates.DateFormatter('%b')

class MonthLetter(minorFmt):
def __init__(self):
DateFormatter.__init__(self, "%b")
def __call__(*args):
s = DateFormatter.__call__(*args)
return s[:1]
minorFmt = MonthLetter()

531     def viewlim\_to\_dt\(self\):

--> 532 vmin, vmax = self.axis.get_view_interval()
533 return num2date(vmin, self.tz), num2date(vmax, self.tz)
534

AttributeError: 'NoneType' object has no attribute 'get_view_interva

From: Eric Firing <efiring@...202...>

To: matplotlib-users@lists.sourceforge.net

Sent: Tuesday, 11 June 2013 6:11 AM
Subject: Re: [Matplotlib-users] time axis format

On 2013/06/10 2:08 PM, Sudheer Joseph wrote:

Thank you,
So there is no way to get J F M A etc with out reducing font size? We
often need to make presentation in front of senior people who insist

for

bigger fonts.
With best regards,
Sudheer

One way is to subclass DateFormatter, e.g.,

class MonthLetter(DateFormatter):
def __init__(self):
DateFormatter.__init__(self, "%b")

 def \_\_call\_\_\(\*args\):
     s = DateFormatter\.\_\_call\_\_\(\*args\)
     return s\[:1\]

class MonthLetterYear(DateFormatter):
def __init__(self):
DateFormatter.__init__(self, "%b\n%Y")

 def \_\_call\_\_\(\*args\):
     s = DateFormatter\.\_\_call\_\_\(\*args\)
     return = s\[:1\] \+ s\[3:\]

...

majorFmt = MonthLetterYear()
minorFmt = MonthLetter()

Not tested, but something like that should work.

Eric

------------------------------------------------------------------------

*From: * Paul Hobson <pmhobson@...287...>;
*To: * Sudheer Joseph <sudheer.joseph@...9...>;
*Cc: * matplotlib-users@lists.sourceforge.net
<matplotlib-users@lists.sourceforge.net>;
*Subject: * Re: [Matplotlib-users] time axis format
*Sent: * Mon, Jun 10, 2013 8:08:18 PM

In that case, I would use ax.tick_params(...) to make the font smaller.

On Sat, Jun 8, 2013 at 7:36 AM, Sudheer Joseph > <sudheer.joseph@...9... >>> <javascript:return>> wrote:

 Dear Paul,
                 The issue I am facing is like in the attached plot
 where the month naming get cluttered\.
 with best regards,
 Sudheer
 \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
 Sudheer Joseph
 Indian National Centre for Ocean Information Services
 Ministry of Earth Sciences, Govt\. of India
 POST BOX NO: 21, IDA Jeedeemetla P\.O\.
 Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55
 Tel:\+91\-40\-23886047\(O\),Fax:\+91\-40\-23895011\(O\),
 Tel:\+91\-40\-23044600\(R\),Tel:\+91\-40\-9440832534\(Mobile\)
 E\-mail:sjo\.India@\.\.\.287\.\.\.
 &lt;javascript:return&gt;;sudheer\.joseph@\.\.\.9\.\.\. 

<javascript:return>

 Web\- http://oppamthadathil.tripod.com
 \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

------------------------------------------------------------------------

     \*From:\* Sudheer Joseph &lt;sudheer\.joseph@\.\.\.9\.\.\.
     &lt;javascript:return&gt;&gt;
     \*To:\* Paul Hobson &lt;pmhobson@\.\.\.287\.\.\. 

<javascript:return>>

     \*Cc:\* &quot;matplotlib\-users@lists\.sourceforge\.net
     &lt;javascript:return&gt;&quot; 

<matplotlib-users@lists.sourceforge.net

     &lt;javascript:return&gt;&gt;
     \*Sent:\* Saturday, 8 June 2013 7:46 PM

     \*Subject:\* Re: \[Matplotlib\-users\] time axis format

     Thank you Paul for the helping hand,
                                        However I was looking for
     slightly different solution like in the attached plots\. I used
     ferret to do this based on the length of the time axis it chose
     the mode of labelling\. for example in case of 2 year plot it
     made month labeling as j f m etc and in case of 1 year as there
     is enough space on x axis it made jan feb etc with single label
     of year\.

     In the attached python plot \(ATser\_RAMA\_HYCOM\_U\_8n90e\.png\) 

every

     tick point is lablled for year, which I wanted to avoid and get
     plots similar to the first types thought it is not done
     automatically but at least manually\.

     \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
     Sudheer Joseph
     Indian National Centre for Ocean Information Services
     Ministry of Earth Sciences, Govt\. of India
     POST BOX NO: 21, IDA Jeedeemetla P\.O\.
     Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55
     Tel:\+91\-40\-23886047\(O\),Fax:\+91\-40\-23895011\(O\),
     Tel:\+91\-40\-23044600\(R\),Tel:\+91\-40\-9440832534\(Mobile\)
     E\-mail:sjo\.India@\.\.\.287\.\.\.
     &lt;javascript:return&gt;;sudheer\.joseph@\.\.\.9\.\.\. 

<javascript:return>

     Web\- http://oppamthadathil.tripod.com
     \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

------------------------------------------------------------------------

         \*From:\* Paul Hobson &lt;pmhobson@\.\.\.287\.\.\. 

<javascript:return>>

         \*To:\* Sudheer Joseph &lt;sudheer\.joseph@\.\.\.2642\.\.\.\.\.
         &lt;javascript:return&gt;&gt;
         \*Cc:\* &quot;matplotlib\-users@\.\.\.564\.\.\.net
         &lt;javascript:return&gt;&quot; 

<matplotlib-users@lists.sourceforge.net

         &lt;javascript:return&gt;&gt;
         \*Sent:\* Friday, 7 June 2013 8:50 PM
         \*Subject:\* Re: \[Matplotlib\-users\] time axis format

         On Thu, Jun 6, 2013 at 11:39 PM, Sudheer Joseph &gt;&gt;&gt;              &lt;sudheer\.joseph@\.\.\.9\.\.\. &lt;javascript:return&gt;&gt;  &gt; wrote:

             Dear Experts,
                          I have been experimenting with the
             plot\_dates option of matplotlib to plot time series 

data

             and have below questions

               I have used
             loc = mdates\.AutoDateLocator\(\)
             ax\.xaxis\.set\_major\_locator\(loc\)

ax.xaxis.set_major_formatter(mpl.dates.DateFormatter('%b\n

             %Y&#39;\)\)

             and got the tick labels in attached plot

             However I feel the repeatd year labeling is not needed
             here and it is required once in a year only , Also if I
             need to plot long time seris insted of &quot;MAR&quot; 

"APR" I

             wanted to get them reduced to &quot;M&quot; 

"A" etc so that the

             lavel congestion can be avoided\.

             I notice that below options are available, but was
             wondering how commbinatins of these locateors are used
             ie mark every month and every year once each\.

             Is there a way to achive the above or does it need
             further development?

             fmt = mdates\.DateFormatter\(&#39;%Y\-%m\-%d&#39;\)
             loc =

mdates.WeekdayLocator(byweekday=mdates.MONDAY,interval=4)

             locator = mdates\.YearLocator\(\)

         If I were trying to do this, I&#39;d cobble something 

together

         using by the minor and major formatters\.
         e\.g\.,\.\.\.
         import matplotlib\.dates as mdates
         import matplotlib\.pyplot as plt

         fig, ax = plt\.subplots\(\)

         majorLocs = mdates\.MonthLocator\(bymonth\[1,7\]\)
         majorFmt = mdates\.DateFormatter\(&#39;%b\\n%Y&#39;\)

         minorLocs = mdates\.MonthLocator\(bymonth\[1,7\]\)
         minorFmt = mdates\.DateFormatter\(&#39;%b&#39;\)

         ax\.xaxis\.set\_major\_locator\(majorLocs\)
         ax\.xaxis\.set\_major\_formatter\(majorFmt\)

         ax\.xaxis\.set\_minor\_locator\(minorLocs\)
         ax\.xaxis\.set\_minor\_formatter\(minorFmt\)

------------------------------------------------------------------------------

This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Thank you Eric and CM,
I have the below piece of code and added the new definition for minorLocs, but gets the below error. I believe I did not fully understand the concept you mentioned.

Try it again, please, exactly as I wrote it.

minorLocs = mdates.MonthLocator(bymonth=[1,3,5,7,9,11],bymonthday=15)

Delete the following line:

minorFmt = mdates.DateFormatter('%b')

Restore the following to what I wrote; your change to the first line is wrong.

···

On 2013/06/10 6:16 PM, Sudheer Joseph wrote:

class MonthLetter(minorFmt):
     def __init__(self):
         DateFormatter.__init__(self, "%b")
     def __call__(*args):
         s = DateFormatter.__call__(*args)
         return s[:1]
minorFmt = MonthLetter()

     531 def viewlim_to_dt(self):
--> 532 vmin, vmax = self.axis.get_view_interval()
     533 return num2date(vmin, self.tz), num2date(vmax, self.tz)
     534

AttributeError: 'NoneType' object has no attribute 'get_view_interva

From: Eric Firing <efiring@...202...>

To: matplotlib-users@lists.sourceforge.net

Sent: Tuesday, 11 June 2013 6:11 AM
Subject: Re: [Matplotlib-users] time axis format

On 2013/06/10 2:08 PM, Sudheer Joseph wrote:

Thank you,
So there is no way to get J F M A etc with out reducing font size? We
often need to make presentation in front of senior people who insist for
bigger fonts.
With best regards,
Sudheer

One way is to subclass DateFormatter, e.g.,

class MonthLetter(DateFormatter):
      def __init__(self):
          DateFormatter.__init__(self, "%b")

      def __call__(*args):
          s = DateFormatter.__call__(*args)
          return s[:1]

class MonthLetterYear(DateFormatter):
      def __init__(self):
          DateFormatter.__init__(self, "%b\n%Y")

      def __call__(*args):
          s = DateFormatter.__call__(*args)
          return = s[:1] + s[3:]

...

majorFmt = MonthLetterYear()
minorFmt = MonthLetter()

Not tested, but something like that should work.

Eric

------------------------------------------------------------------------
*From: * Paul Hobson <pmhobson@...287...>;
*To: * Sudheer Joseph <sudheer.joseph@...9...>;
*Cc: * matplotlib-users@lists.sourceforge.net
<matplotlib-users@lists.sourceforge.net>;
*Subject: * Re: [Matplotlib-users] time axis format
*Sent: * Mon, Jun 10, 2013 8:08:18 PM

In that case, I would use ax.tick_params(...) to make the font smaller.

On Sat, Jun 8, 2013 at 7:36 AM, Sudheer Joseph <sudheer.joseph@...9... >>> <javascript:return>> wrote:

      Dear Paul,
                      The issue I am facing is like in the attached plot
      where the month naming get cluttered.
      with best regards,
      Sudheer
      ***************************************************************
      Sudheer Joseph
      Indian National Centre for Ocean Information Services
      Ministry of Earth Sciences, Govt. of India
      POST BOX NO: 21, IDA Jeedeemetla P.O.
      Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55
      Tel:+91-40-23886047(O),Fax:+91-40-23895011(O),
      Tel:+91-40-23044600(R),Tel:+91-40-9440832534(Mobile)
      E-mail:sjo.India@...287...
      <javascript:return>;sudheer.joseph@...9... <javascript:return>
      Web- http://oppamthadathil.tripod.com
      ***************************************************************

          ------------------------------------------------------------------------
          *From:* Sudheer Joseph <sudheer.joseph@...9...
          <javascript:return>>
          *To:* Paul Hobson <pmhobson@...287... <javascript:return>>
          *Cc:* "matplotlib-users@lists.sourceforge.net
          <javascript:return>" <matplotlib-users@lists.sourceforge.net
          <javascript:return>>
          *Sent:* Saturday, 8 June 2013 7:46 PM

          *Subject:* Re: [Matplotlib-users] time axis format

          Thank you Paul for the helping hand,
                                             However I was looking for
          slightly different solution like in the attached plots. I used
          ferret to do this based on the length of the time axis it chose
          the mode of labelling. for example in case of 2 year plot it
          made month labeling as j f m etc and in case of 1 year as there
          is enough space on x axis it made jan feb etc with single label
          of year.

          In the attached python plot (ATser_RAMA_HYCOM_U_8n90e.png) every
          tick point is lablled for year, which I wanted to avoid and get
          plots similar to the first types thought it is not done
          automatically but at least manually.

          ***************************************************************
          Sudheer Joseph
          Indian National Centre for Ocean Information Services
          Ministry of Earth Sciences, Govt. of India
          POST BOX NO: 21, IDA Jeedeemetla P.O.
          Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55
          Tel:+91-40-23886047(O),Fax:+91-40-23895011(O),
          Tel:+91-40-23044600(R),Tel:+91-40-9440832534(Mobile)
          E-mail:sjo.India@...287...
          <javascript:return>;sudheer.joseph@...9... <javascript:return>
          Web- http://oppamthadathil.tripod.com
          ***************************************************************

              ------------------------------------------------------------------------
              *From:* Paul Hobson <pmhobson@...287... <javascript:return>>
              *To:* Sudheer Joseph <sudheer.joseph@...9...
              <javascript:return>>
              *Cc:* "matplotlib-users@lists.sourceforge.net
              <javascript:return>" <matplotlib-users@lists.sourceforge.net
              <javascript:return>>
              *Sent:* Friday, 7 June 2013 8:50 PM
              *Subject:* Re: [Matplotlib-users] time axis format

              On Thu, Jun 6, 2013 at 11:39 PM, Sudheer Joseph >>> <sudheer.joseph@...9... <javascript:return>> wrote:

                  Dear Experts,
                               I have been experimenting with the
                  plot_dates option of matplotlib to plot time series data
                  and have below questions

                    I have used
                  loc = mdates.AutoDateLocator()
                  ax.xaxis.set_major_locator(loc)
                  ax.xaxis.set_major_formatter(mpl.dates.DateFormatter('%b\n
                  %Y'))

                  and got the tick labels in attached plot

                  However I feel the repeatd year labeling is not needed
                  here and it is required once in a year only , Also if I
                  need to plot long time seris insted of "MAR" "APR" I
                  wanted to get them reduced to "M" "A" etc so that the
                  lavel congestion can be avoided.

                  I notice that below options are available, but was
                  wondering how commbinatins of these locateors are used
                  ie mark every month and every year once each.

                  Is there a way to achive the above or does it need
                  further development?

                  fmt = mdates.DateFormatter('%Y-%m-%d')
                  loc =
                  mdates.WeekdayLocator(byweekday=mdates.MONDAY,interval=4)
                  locator = mdates.YearLocator()

              If I were trying to do this, I'd cobble something together
              using by the minor and major formatters.
              e.g.,...
              import matplotlib.dates as mdates
              import matplotlib.pyplot as plt

              fig, ax = plt.subplots()

              majorLocs = mdates.MonthLocator(bymonth[1,7])
              majorFmt = mdates.DateFormatter('%b\n%Y')

              minorLocs = mdates.MonthLocator(bymonth[1,7])
              minorFmt = mdates.DateFormatter('%b')

              ax.xaxis.set_major_locator(majorLocs)
              ax.xaxis.set_major_formatter(majorFmt)

              ax.xaxis.set_minor_locator(minorLocs)
              ax.xaxis.set_minor_formatter(minorFmt)

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Thank you Eric and CM,
I have the below piece of code and added the new definition for minorLocs, but gets the below error. I believe I did not fully understand the concept you mentioned.

The concept is "subclassing": writing a class that "inherits" most of its behavior from another class, while modifying some aspects.

minorLocs = mdates.MonthLocator(bymonth=[1,3,5,7,9,11],bymonthday=15)
minorFmt = mdates.DateFormatter('%b')

The problem with your change to the following is that MonthLetter should be subclassing DateFormatter, as I had it. With your change it is trying to subclass an instance of DateFormatter, not the class itself.

class MonthLetter(minorFmt):
     def __init__(self):
         DateFormatter.__init__(self, "%b")
     def __call__(*args):
         s = DateFormatter.__call__(*args)
         return s[:1]
minorFmt = MonthLetter()

In the context of your usage, the one change you do need to make to the way I wrote the subclasses is to change my "DateFormatter" to "mdates.DateFormatter", since you are importing mdates rather than doing

from matplotlib.dates import DateFormatter

(Or, you can add the above import line to your block of imports.)

Eric

···

On 2013/06/10 6:16 PM, Sudheer Joseph wrote:

Thank you very much Eric for your valuable suggestions and explanations, now I could follow what exactly was wrong with my way of doing it, I got the result correctly.
thanks a lot
with best regards,
Sudheer

···

----- Original Message -----

From: Eric Firing <efiring@...202...>
To: Sudheer Joseph <sudheer.joseph@...9...>
Cc: "matplotlib-users@lists.sourceforge.net" <matplotlib-users@...1544...ceforge.net>
Sent: Tuesday, 11 June 2013 12:53 PM
Subject: Re: [Matplotlib-users] time axis format

On 2013/06/10 6:16 PM, Sudheer Joseph wrote:

Thank you Eric and CM,
I have the below piece of code and added the new definition for minorLocs,

but gets the below error. I believe I did not fully understand the concept you
mentioned.

Try it again, please, exactly as I wrote it.

minorLocs = mdates.MonthLocator(bymonth=[1,3,5,7,9,11],bymonthday=15)

Delete the following line:

minorFmt = mdates.DateFormatter('%b')

Restore the following to what I wrote; your change to the first line is
wrong.

class MonthLetter(minorFmt):
def __init__(self):
DateFormatter.__init__(self, "%b")
def __call__(*args):
s = DateFormatter.__call__(*args)
return s[:1]
minorFmt = MonthLetter()

  531     def viewlim\_to\_dt\(self\):

--> 532 vmin, vmax = self.axis.get_view_interval()
533 return num2date(vmin, self.tz), num2date(vmax, self.tz)
534

AttributeError: 'NoneType' object has no attribute

'get_view_interva

From: Eric Firing <efiring@...202...>

To: matplotlib-users@lists.sourceforge.net

Sent: Tuesday, 11 June 2013 6:11 AM
Subject: Re: [Matplotlib-users] time axis format

On 2013/06/10 2:08 PM, Sudheer Joseph wrote:

Thank you,
So there is no way to get J F M A etc with out reducing font size?

We

often need to make presentation in front of senior people who

insist for

bigger fonts.
With best regards,
Sudheer

One way is to subclass DateFormatter, e.g.,

class MonthLetter(DateFormatter):
def __init__(self):
DateFormatter.__init__(self, "%b")

   def \_\_call\_\_\(\*args\):
       s = DateFormatter\.\_\_call\_\_\(\*args\)
       return s\[:1\]

class MonthLetterYear(DateFormatter):
def __init__(self):
DateFormatter.__init__(self, "%b\n%Y")

   def \_\_call\_\_\(\*args\):
       s = DateFormatter\.\_\_call\_\_\(\*args\)
       return = s\[:1\] \+ s\[3:\]

...

majorFmt = MonthLetterYear()
minorFmt = MonthLetter()

Not tested, but something like that should work.

Eric

------------------------------------------------------------------------

*From: * Paul Hobson <pmhobson@...287...>;
*To: * Sudheer Joseph <sudheer.joseph@...9...>;
*Cc: * matplotlib-users@lists.sourceforge.net
<matplotlib-users@lists.sourceforge.net>;
*Subject: * Re: [Matplotlib-users] time axis format
*Sent: * Mon, Jun 10, 2013 8:08:18 PM

In that case, I would use ax.tick_params(...) to make the font

smaller.

On Sat, Jun 8, 2013 at 7:36 AM, Sudheer Joseph > <sudheer.joseph@...9... >>>> <javascript:return>> wrote:

   Dear Paul,
                   The issue I am facing is like in the attached 

plot

   where the month naming get cluttered\.
   with best regards,
   Sudheer

***************************************************************

   Sudheer Joseph
   Indian National Centre for Ocean Information Services
   Ministry of Earth Sciences, Govt\. of India
   POST BOX NO: 21, IDA Jeedeemetla P\.O\.
   Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55
   Tel:\+91\-40\-23886047\(O\),Fax:\+91\-40\-23895011\(O\),
   Tel:\+91\-40\-23044600\(R\),Tel:\+91\-40\-9440832534\(Mobile\)
   E\-mail:sjo\.India@\.\.\.287\.\.\.
   &lt;javascript:return&gt;;sudheer\.joseph@\.\.\.9\.\.\. 

<javascript:return>

   Web\- http://oppamthadathil.tripod.com

***************************************************************

------------------------------------------------------------------------

       \*From:\* Sudheer Joseph &lt;sudheer\.joseph@\.\.\.9\.\.\.
       &lt;javascript:return&gt;&gt;
       \*To:\* Paul Hobson &lt;pmhobson@\.\.\.287\.\.\. 

<javascript:return>>

       \*Cc:\* &quot;matplotlib\-users@lists\.sourceforge\.net
       &lt;javascript:return&gt;&quot; 

<matplotlib-users@lists.sourceforge.net

       &lt;javascript:return&gt;&gt;
       \*Sent:\* Saturday, 8 June 2013 7:46 PM

       \*Subject:\* Re: \[Matplotlib\-users\] time axis format

       Thank you Paul for the helping hand,
                                          However I was looking 

for

       slightly different solution like in the attached plots\. I 

used

       ferret to do this based on the length of the time axis it 

chose

       the mode of labelling\. for example in case of 2 year plot 

it

       made month labeling as j f m etc and in case of 1 year as 

there

       is enough space on x axis it made jan feb etc with single 

label

       of year\.

       In the attached python plot 

(ATser_RAMA_HYCOM_U_8n90e.png) every

       tick point is lablled for year, which I wanted to avoid 

and get

       plots similar to the first types thought it is not done
       automatically but at least manually\.

***************************************************************

       Sudheer Joseph
       Indian National Centre for Ocean Information Services
       Ministry of Earth Sciences, Govt\. of India
       POST BOX NO: 21, IDA Jeedeemetla P\.O\.
       Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55
       Tel:\+91\-40\-23886047\(O\),Fax:\+91\-40\-23895011\(O\),
       Tel:\+91\-40\-23044600\(R\),Tel:\+91\-40\-9440832534\(Mobile\)
       E\-mail:sjo\.India@\.\.\.287\.\.\.
       &lt;javascript:return&gt;;sudheer\.joseph@\.\.\.9\.\.\. 

<javascript:return>

       Web\- http://oppamthadathil.tripod.com

***************************************************************

------------------------------------------------------------------------

           \*From:\* Paul Hobson &lt;pmhobson@\.\.\.287\.\.\. 

<javascript:return>>

           \*To:\* Sudheer Joseph &lt;sudheer\.joseph@\.\.\.1762\.\.\.\.\.\.
           &lt;javascript:return&gt;&gt;
           \*Cc:\* &quot;matplotlib\-users@\.\.\.1738\.\.\.\.net
           &lt;javascript:return&gt;&quot; 

<matplotlib-users@lists.sourceforge.net

           &lt;javascript:return&gt;&gt;
           \*Sent:\* Friday, 7 June 2013 8:50 PM
           \*Subject:\* Re: \[Matplotlib\-users\] time axis format

           On Thu, Jun 6, 2013 at 11:39 PM, Sudheer Joseph &gt;&gt;&gt;&gt;                &lt;sudheer\.joseph@\.\.\.9\.\.\.  &gt; &lt;javascript:return&gt;&gt; wrote:

               Dear Experts,
                            I have been experimenting with the
               plot\_dates option of matplotlib to plot time 

series data

               and have below questions

                 I have used
               loc = mdates\.AutoDateLocator\(\)
               ax\.xaxis\.set\_major\_locator\(loc\)

ax.xaxis.set_major_formatter(mpl.dates.DateFormatter('%b\n

               %Y&#39;\)\)

               and got the tick labels in attached plot

               However I feel the repeatd year labeling is not 

needed

               here and it is required once in a year only , 

Also if I

               need to plot long time seris insted of 

"MAR" "APR" I

               wanted to get them reduced to &quot;M&quot; 

"A" etc so that the

               lavel congestion can be avoided\.

               I notice that below options are available, but 

was

               wondering how commbinatins of these locateors are 

used

               ie mark every month and every year once each\.

               Is there a way to achive the above or does it 

need

               further development?

               fmt = mdates\.DateFormatter\(&#39;%Y\-%m\-%d&#39;\)
               loc =

mdates.WeekdayLocator(byweekday=mdates.MONDAY,interval=4)

               locator = mdates\.YearLocator\(\)

           If I were trying to do this, I&#39;d cobble something 

together

           using by the minor and major formatters\.
           e\.g\.,\.\.\.
           import matplotlib\.dates as mdates
           import matplotlib\.pyplot as plt

           fig, ax = plt\.subplots\(\)

           majorLocs = mdates\.MonthLocator\(bymonth\[1,7\]\)
           majorFmt = mdates\.DateFormatter\(&#39;%b\\n%Y&#39;\)

           minorLocs = mdates\.MonthLocator\(bymonth\[1,7\]\)
           minorFmt = mdates\.DateFormatter\(&#39;%b&#39;\)

           ax\.xaxis\.set\_major\_locator\(majorLocs\)
           ax\.xaxis\.set\_major\_formatter\(majorFmt\)

           ax\.xaxis\.set\_minor\_locator\(minorLocs\)
           ax\.xaxis\.set\_minor\_formatter\(minorFmt\)

------------------------------------------------------------------------------

This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

------------------------------------------------------------------------------

This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options