[matplotlib] Overlapping axis text

Discussion in 'Python' started by Durand, Sep 6, 2008.

  1. Durand

    Durand Guest

    I got a really annoying problem with datetime graphs. The problem is
    that with a long range time graph, the text on the x axis keeps
    overlapping like here: http://durand.zephyrhosting.net/tremcs/graph_all.png

    Would there be any way to fix this? I was thinking of rotating the
    text so that there was enough space for each one but the best solution
    would be to only display text with the right scale. IE, with a 7 day
    graph, each day would have text, with a year long graph, each month
    would be displayed, etc...

    This is the code I use at the moment but its pretty messy:

    import dateutil,pylab
    from matplotlib.dates import MonthLocator, WeekdayLocator

    fig = pylab.figure()
    ax = fig.add_subplot(111)
    days = MonthLocator() # every monday
    months = MonthLocator() # every month
    ax.xaxis.set_major_locator(months)
    ax.xaxis.set_minor_locator(days)

    pylab.plot_date(pylab.date2num(dates), allkills, '.-', color='blue')
    pylab.plot_date(pylab.date2num(dates), alldeaths, '.-',
    color='red')
    pylab.plot_date(pylab.date2num(dates), kills, '.-',
    color='darkgreen')
    pylab.plot_date(pylab.date2num(dates), deaths, '.-',
    color='orange')
    if legend == 1:
    pylab.legend(("Total Kills","Total Deaths", "Single
    Session Kills", "Single Session Deaths"), 'lower left')
    pylab.xlabel('Date')
    pylab.ylabel('Stats')
    ax2 = pylab.twinx()
    pylab.plot_date(pylab.date2num(dates), allratio, '.-',
    color='purple')
    pylab.plot_date(pylab.date2num(dates), ratio, '.-',
    color='yellow')
    pylab.ylabel('Ratio')
    ax2.yaxis.tick_right()
    pylab.show()
    Please excuse the extra tabbing, it's part of an if statement.
    Durand, Sep 6, 2008
    #1
    1. Advertising

  2. Durand

    Durand Guest

    Re: Overlapping axis text

    Err...made a mistake there.

    days = WeekdayLocator() # every monday
    months = MonthLocator() # every month

    That doesn't change my question though.

    Thanks
    Durand, Sep 6, 2008
    #2
    1. Advertising

  3. Durand

    McBuell Guest

    McBuell, Nov 10, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    921
  2. Dr. Colombes
    Replies:
    3
    Views:
    660
    John Hunter
    Feb 23, 2005
  3. Caleb Hattingh
    Replies:
    2
    Views:
    22,971
    Caleb Hattingh
    Mar 31, 2006
  4. Replies:
    2
    Views:
    612
    Bergamot
    Apr 20, 2007
  5. Dick Crepeau

    Matplotlib axis control problem

    Dick Crepeau, Oct 17, 2007, in forum: Python
    Replies:
    0
    Views:
    1,508
    Dick Crepeau
    Oct 17, 2007
Loading...

Share This Page