[matplotlib] Overlapping axis text

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Durand

    [matplotlib] Overlapping axis text

    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.date s import MonthLocator, WeekdayLocator

    fig = pylab.figure()
    ax = fig.add_subplot (111)
    days = MonthLocator() # every monday
    months = MonthLocator() # every month
    ax.xaxis.set_ma jor_locator(mon ths)
    ax.xaxis.set_mi nor_locator(day s)

    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='darkgree n')
    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('D ate')
    pylab.ylabel('S tats')
    ax2 = pylab.twinx()
    pylab.plot_date (pylab.date2num (dates), allratio, '.-',
    color='purple')
    pylab.plot_date (pylab.date2num (dates), ratio, '.-',
    color='yellow')
    pylab.ylabel('R atio')
    ax2.yaxis.tick_ right()
    pylab.show()
    Please excuse the extra tabbing, it's part of an if statement.
  • Durand

    #2
    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

    Comment

    • McBuell

      #3
      Re: Overlapping axis text


      try this:

      fig.autofmt_xda te()

      should help a lot =)

      Cheers
      --
      View this message in context: http://www.nabble.com/-matplotlib--O...p20430433.html
      Sent from the Python - python-list mailing list archive at Nabble.com.

      Comment

      Working...