Browse Source

Add box documentation and x/y labels with labels documentation.

pull/264/head
Florian Mounier 10 years ago
parent
commit
7da1e05980
  1. 5
      docs/changelog.rst
  2. 42
      docs/documentation/configuration/label.rst
  3. 31
      docs/documentation/types/box.rst
  4. 2
      pygal/__init__.py
  5. 9
      pygal/graph/box.py
  6. 4
      pygal/graph/graph.py

5
docs/changelog.rst

@ -2,6 +2,11 @@
Changelog Changelog
========= =========
2.0.1 UNRELEASED
================
* Fix the missing title on x_labels with labels.
2.0.0 2.0.0
===== =====
* Rework the ghost mechanism to come back to a more object oriented behavior, storing all state in a state object which is created on every render. (#161) * Rework the ghost mechanism to come back to a more object oriented behavior, storing all state in a state object which is created on every render. (#161)

42
docs/documentation/configuration/label.rst

@ -14,6 +14,34 @@ x_labels
chart.x_labels = 'Red', 'Blue', 'Green' chart.x_labels = 'Red', 'Blue', 'Green'
chart.add('line', [.0002, .0005, .00035]) chart.add('line', [.0002, .0005, .00035])
It is possible for dual charts to define a custom scale:
.. pygal-code::
chart = pygal.XY()
chart.x_labels = (.00012, .00024, .00048, .00096)
chart.add('line', [(.0002, 10), (.0005, 20), (.00035, 15)])
And in this case it is possible to set text labels in place of values:
.. pygal-code::
chart = pygal.XY()
chart.x_labels = ({
'label': 'Twelve',
'value': .00012
}, {
'label': 'Twenty four',
'value': .00024
}, {
'label': 'Forty eight',
'value': .00048
}, {
'label': 'Ninety six',
'value': .00096})
chart.add('line', [(.0002, 10), (.0005, 20), (.00035, 15)])
y_labels y_labels
-------- --------
@ -25,6 +53,20 @@ y_labels
chart.add('line', [.0002, .0005, .00035]) chart.add('line', [.0002, .0005, .00035])
It is now possible to add text to labels values:
.. pygal-code::
chart = pygal.Line()
chart.y_labels = [
{'label': 'One', 'value': .0001},
{'label': 'Three', 'value': .0003},
{'label': 'Four', 'value': .0004},
{'label': 'Four and a half', 'value': .00045},
{'label': 'Five', 'value': .0005}]
chart.add('line', [.0002, .0005, .00035])
show_x_labels show_x_labels
------------- -------------

31
docs/documentation/types/box.rst

@ -1,10 +1,11 @@
Box Box
--- ---
Basic
~~~~~
Here's some whiskers: Extremes (default)
~~~~~~~~~~~~~~~~~~
By default, the extremes mode is used that is the whiskers are the extremes of the data set, the box goes from the first quartile to the third and the middle line is the median.
.. pygal-code:: .. pygal-code::
@ -15,7 +16,11 @@ Here's some whiskers:
box_plot.add('Opera', [3472, 2933, 4203, 5229, 5810, 1828, 9013, 4669]) box_plot.add('Opera', [3472, 2933, 4203, 5229, 5810, 1828, 9013, 4669])
box_plot.add('IE', [43, 41, 59, 79, 144, 136, 34, 102]) box_plot.add('IE', [43, 41, 59, 79, 144, 136, 34, 102])
and variations:
1.5 interquartile range
~~~~~~~~~~~~~~~~~~~~~~~
Same as above except the whiskers are the first quartile minus 1.5 times the interquartile range and the third quartile plus 1.5 times the interquartile range.
.. pygal-code:: .. pygal-code::
@ -26,6 +31,12 @@ and variations:
box_plot.add('Opera', [3472, 2933, 4203, 5229, 5810, 1828, 9013, 4669]) box_plot.add('Opera', [3472, 2933, 4203, 5229, 5810, 1828, 9013, 4669])
box_plot.add('IE', [43, 41, 59, 79, 144, 136, 34, 102]) box_plot.add('IE', [43, 41, 59, 79, 144, 136, 34, 102])
Tukey
~~~~~
The whiskers are the lowest datum whithin the 1.5 IQR of the lower quartile and the highest datum still within 1.5 IQR of the upper quartile. The outliers are shown too.
.. pygal-code:: .. pygal-code::
box_plot = pygal.Box(box_mode="tukey") box_plot = pygal.Box(box_mode="tukey")
@ -35,6 +46,12 @@ and variations:
box_plot.add('Opera', [3472, 2933, 4203, 5229, 5810, 1828, 9013, 4669]) box_plot.add('Opera', [3472, 2933, 4203, 5229, 5810, 1828, 9013, 4669])
box_plot.add('IE', [43, 41, 59, 79, 144, 136, 34, 102]) box_plot.add('IE', [43, 41, 59, 79, 144, 136, 34, 102])
Standard deviation
~~~~~~~~~~~~~~~~~~
The whiskers are defined here by the standard deviation of the data.
.. pygal-code:: .. pygal-code::
box_plot = pygal.Box(box_mode="stdev") box_plot = pygal.Box(box_mode="stdev")
@ -44,6 +61,12 @@ and variations:
box_plot.add('Opera', [3472, 2933, 4203, 5229, 5810, 1828, 9013, 4669]) box_plot.add('Opera', [3472, 2933, 4203, 5229, 5810, 1828, 9013, 4669])
box_plot.add('IE', [43, 41, 59, 79, 144, 136, 34, 102]) box_plot.add('IE', [43, 41, 59, 79, 144, 136, 34, 102])
Population standard deviation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The whiskers are defined here by the population standard deviation of the data.
.. pygal-code:: .. pygal-code::
box_plot = pygal.Box(box_mode="pstdev") box_plot = pygal.Box(box_mode="pstdev")

2
pygal/__init__.py

@ -24,7 +24,7 @@ and the maps extensions namespace module.
""" """
__version__ = '2.0.0' __version__ = '2.0.1'
import pkg_resources import pkg_resources
import sys import sys

9
pygal/graph/box.py

@ -179,12 +179,12 @@ class Box(Graph):
@staticmethod @staticmethod
def _box_points(values, mode='extremes'): def _box_points(values, mode='extremes'):
""" """
Default mode: (mode='1.5IQR' or unset) Default mode: (mode='extremes' or unset)
Return a 7-tuple of min, Q1 - 1.5 * IQR, Q1, Median, Q3,
Q3 + 1.5 * IQR and max for a list of numeric values.
Extremes mode: (mode='extremes')
Return a 7-tuple of 2x minimum, Q1, Median, Q3, Return a 7-tuple of 2x minimum, Q1, Median, Q3,
and 2x maximum for a list of numeric values. and 2x maximum for a list of numeric values.
1.5IQR mode: (mode='1.5IQR')
Return a 7-tuple of min, Q1 - 1.5 * IQR, Q1, Median, Q3,
Q3 + 1.5 * IQR and max for a list of numeric values.
Tukey mode: (mode='tukey') Tukey mode: (mode='tukey')
Return a 7-tuple of min, q[0..4], max and a list of outliers Return a 7-tuple of min, q[0..4], max and a list of outliers
Outliers are considered values x: x < q1 - IQR or x > q3 + IQR Outliers are considered values x: x < q1 - IQR or x > q3 + IQR
@ -195,7 +195,6 @@ class Box(Graph):
Return a 7-tuple of min, q[0..4], max and a list of outliers Return a 7-tuple of min, q[0..4], max and a list of outliers
Outliers are considered values x: x < q2 - SDp or x > q2 + SDp Outliers are considered values x: x < q2 - SDp or x > q2 + SDp
The iterator values may include None values. The iterator values may include None values.
Uses quartile definition from Mendenhall, W. and Uses quartile definition from Mendenhall, W. and

4
pygal/graph/graph.py

@ -173,6 +173,10 @@ class Graph(PublicApi):
text.text = truncate(label, truncation) text.text = truncate(label, truncation)
if text.text != label: if text.text != label:
self.svg.node(guides, 'title').text = label self.svg.node(guides, 'title').text = label
else:
self.svg.node(
guides, 'title',
).text = self._x_format(position)
if self.x_label_rotation: if self.x_label_rotation:
text.attrib['transform'] = "rotate(%d %f %f)" % ( text.attrib['transform'] = "rotate(%d %f %f)" % (

Loading…
Cancel
Save