~ubuntu-branches/ubuntu/utopic/python-chaco/utopic

« back to all changes in this revision

Viewing changes to docs/source/scales.rst

  • Committer: Package Import Robot
  • Author(s): Andrew Starr-Bochicchio
  • Date: 2014-06-01 17:04:08 UTC
  • mfrom: (7.2.5 sid)
  • Revision ID: package-import@ubuntu.com-20140601170408-m86xvdjd83a4qon0
Tags: 4.4.1-1ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
 - Let the binary-predeb target work on the usr/lib/python* directory
   as we don't have usr/share/pyshared anymore.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
******************************
2
 
About the Chaco Scales package
3
 
******************************
4
 
 
5
 
In the summer of 2007, I spent a few weeks working through the axis  
6
 
ticking and labelling problem.  The basic goal was that I wanted to  
7
 
create a flexible ticking system that would produce nicely-spaced axis  
8
 
labels for arbitrary sets of labels *and* arbitrary intervals.  The  
9
 
chaco2.scales package is the result of this effort.  It is an entirely  
10
 
standalone package that does not import from any other Enthought  
11
 
package (not even traits!), and the idea was that it could be used in  
12
 
other plotting packages as well.
13
 
 
14
 
The overall idea is that you create a ScaleSystem consisting of  
15
 
various Scales.  When the ScaleSystem is presented with a data range  
16
 
(low,high) and a screen space amount, it searches through its list of  
17
 
scales for the scale that produces the "nicest" set of labels.  It  
18
 
takes into account whitespace, the formatted size of labels produced  
19
 
by each scale in the ScaleSystem, etc.  So, the basic numerical Scales  
20
 
defined in scales.py are:
21
 
 
22
 
* FixedScale: Simple scale with a fixed interval; places ticks at
23
 
  multiples of the resolution
24
 
* DefaultScale: Scale that tries to place ticks at 1,2,5, and 10 so  that
25
 
  ticks don't "pop" or suddenly jump when the resolution changes  (when
26
 
  zooming)
27
 
* LogScale: Dynamic scale that only produces ticks and labels that  work
28
 
  well when doing logarithmic plots
29
 
 
30
 
By comparison, the default ticking logic in DefaultTickGenerator (in  
31
 
ticks.py) is basically just the DefaultScale.  (This is currently the  
32
 
default tick generator used by PlotAxis.)
33
 
 
34
 
In time_scale.py, I define an additional scale, the TimeScale.   
35
 
TimeScale not only handles time-oriented data using units of uniform  
36
 
interval (microseconds up to days and weeks), it also handles non- 
37
 
uniform calendar units like "day of the month" and "month of the  
38
 
year".  So, you can tell Chaco to generate ticks on the 1st of every  
39
 
month, and it will give you non-uniformly spaced tick and grid lines.
40
 
 
41
 
The scale system mechanism is configurable, so although all of the  
42
 
examples use the CalendarScaleSystem, you don't have to use it.  In  
43
 
fact, if you look at CalendarScaleSystem.__init__, it just initializes  
44
 
its list of scales with ``HMSScales + MDYScales``::
45
 
 
46
 
    HMSScales = [TimeScale(microseconds=1), TimeScale(milliseconds=1)] + \
47
 
               [TimeScale(seconds=dt) for dt in (1, 5, 15, 30)] + \
48
 
               [TimeScale(minutes=dt) for dt in (1, 5, 15, 30)] + \
49
 
               [TimeScale(hours=dt) for dt in (1, 2, 3, 4, 6, 12, 24)]
50
 
 
51
 
    MDYScales = [TimeScale(day_of_month=range(1,31,3)),
52
 
                TimeScale(day_of_month=(1,8,15,22)),
53
 
                TimeScale(day_of_month=(1,15)),
54
 
                TimeScale(month_of_year=range(1,13)),
55
 
                TimeScale(month_of_year=range(1,13,3)),
56
 
                TimeScale(month_of_year=(1,7)),
57
 
                TimeScale(month_of_year=(1,))]
58
 
 
59
 
So, if you wanted to create your own ScaleSystem with days, weeks, and  
60
 
whatnot, you could do::
61
 
 
62
 
    ExtendedScales = HSMScales + [TimeScale(days=n) for n in (1,7,14,28)]
63
 
    MyScaleSystem = CalendarScaleSystem(*ExtendedScales)
64
 
 
65
 
To use the Scales package in your Chaco plots, just import :class:`PlotAxis` from
66
 
:mod:`chaco2.scales_axis` instead of :mod:`chaco2.axis`.  You will still need to create a
67
 
:class:`ScalesTickGenerator` and pass it in.  The financial_plot_dates.py demo is a
68
 
good example of how to do this.
69