Skip to content

Commit

Permalink
Merge pull request #22 from sivasankariit/master
Browse files Browse the repository at this point in the history
Support for broken-horizontal-bars
  • Loading branch information
alexras committed Nov 7, 2012
2 parents ba295fd + ee20a66 commit aae276b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
70 changes: 70 additions & 0 deletions BrokenBarH.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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]]
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__all__ = ["Bar", "Plot", "PlotLayout", "WeightedPlotLayout",
"Scatter", "ClusteredBars", "PlotInfo", "Line", "VLine", "HLine",
"Utils", "BoxAndWhisker", "StackedBars", "Label", "StackedLines",
"BrokenAxisPlot"]
"BrokenAxisPlot", "BrokenBarH"]

for __mySrcDir__ in __all__:
exec("from %s import *" % (__mySrcDir__))

0 comments on commit aae276b

Please sign in to comment.