-
Notifications
You must be signed in to change notification settings - Fork 4
/
BrokenBarH.py
70 lines (57 loc) · 1.9 KB
/
BrokenBarH.py
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
61
62
63
64
65
66
67
68
69
70
from matplotlib import pyplot
from PlotInfo import PlotInfo
class BrokenBarH(PlotInfo):
"""
A plot element that represents a collection of horizontal bars spanning a
sequence of [xMin, xMax] ranges at a given y.
"""
def __init__(self,
y=None,
xMins = [],
xWidths = [],
yWidth=0.6,
linewidth=1.0,
color="black",
edgeColor=None,
**kwargs):
super(BrokenBarH,self).__init__("broken barh", **kwargs)
self.y = y
"""
The y coordinate for this collection of horizontal bars
"""
self.xMins = xMins
"""
A list of locations for the start xValues of the horizontal bars
"""
self.xWidths = xWidths
"""
A list of widths of the horizontal bars
"""
self.yWidth = yWidth
"""
The bar's width along the y axis
"""
self.linewidth = linewidth
"""
The width of the line that borders the bars
"""
self.color = color
"""
The bar's color. See :ref:`styling-colors` for valid colors.
"""
self.edgeColor = edgeColor
"""
The color of the line that borders the bars
"""
def draw(self, fig, axis, transform=None):
# Draw only if we have a valid y value for the horizontal bars
if self.y is None:
return [[], []]
xranges = [(self.xMins[i], self.xWidths[i]) for i in xrange(len(self.xMins))]
yrange = (self.y - 0.5 * self.yWidth, self.yWidth)
kwdict = self.getAttributes()
kwdict["linewidth"] = self.linewidth
kwdict["edgecolor"] = self.edgeColor
kwdict["facecolors"] = self.color
kwdict["label"] = self.label
return [[axis.broken_barh(xranges, yrange, **kwdict)], [self.label]]