File: dashtick.py

package info (click to toggle)
matplotlib 0.98.1-1%2Blenny4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 18,624 kB
  • ctags: 22,599
  • sloc: python: 76,915; cpp: 63,459; ansic: 5,353; makefile: 111; sh: 12
file content (60 lines) | stat: -rw-r--r-- 1,685 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Matplotlib xaxis label tweak

import sys
import matplotlib
from matplotlib import pylab, ticker

ROTATION=75
DASHROTATION=75
DASHBASE=10
DASHLEN=35
DASHSTAGGER=3
FONTSIZE=6

def dashlen(step):
    return DASHBASE+(DASHLEN*(step%DASHSTAGGER))

def test_dashticklabel():
    pylab.clf()
    x = [0.0, 1.0, 1.1, 5.0, 5.1, 6.0]
    y = [1, 3, 2, 5, 1, 2]
    labels = ['foo', 'bar', 'baz', 'alpha', 'beta', 'gamma']
    locator = ticker.FixedLocator(x)
    formatter = ticker.FixedFormatter(labels)
    axis = pylab.axes([0.3, 0.3, 0.4, 0.4])
    axis.xaxis.set_major_locator(locator)
    axis.xaxis.set_major_formatter(formatter)
    axis.yaxis.set_major_locator(locator)
    axis.yaxis.set_major_formatter(formatter)
    for tick in axis.xaxis.get_major_ticks():
        tick.label2On = True
    for tick in axis.yaxis.get_major_ticks():
        tick.label2On = True
    step = 0
    for label in axis.get_xticklabels():
        pylab.setp(label,
                   rotation=ROTATION,
                   dashlength=dashlen(step),
                   dashrotation=DASHROTATION,
                   fontsize=FONTSIZE,
                  )
        step += 1
    step = 0
    for label in axis.get_yticklabels():
        pylab.setp(label,
                   rotation=90-ROTATION,
                   dashlength=dashlen(step),
                   dashrotation=90-DASHROTATION,
                   fontsize=FONTSIZE,
                  )
        step += 1
    pylab.xlabel('X Label')
    pylab.ylabel('Y Label')
    pylab.plot(x, y)
    axis.set_xlim((0.0, 6.0))
    axis.set_ylim((0.0, 6.0))
    pylab.savefig('dashticklabel')
    pylab.show()

if __name__ == '__main__':
    test_dashticklabel()