Skip to content

Commit b7ccd97

Browse files
committed
Integrating minimum version check utility function into the rest of the code.
1 parent 4c16e4e commit b7ccd97

File tree

5 files changed

+21
-37
lines changed

5 files changed

+21
-37
lines changed

Legend.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from Location import Location
22
import warnings
3+
from Utils import _check_min_matplotlib_version
34

45
class Legend(object):
56
# Location, location, location!
@@ -17,11 +18,7 @@ def _genLegendKeywords(self, axes, handles, labels):
1718
legendKeywords = {}
1819

1920
if self.columns > 1:
20-
versionParts = [int(x) for x in matplotlib.__version__.split('.')]
21-
22-
(superMajor, major, minor) = versionParts[0:3]
23-
24-
if superMajor == 0 and major < 98:
21+
if not _check_min_matplotlib_version(0, 98, 0):
2522
warnings.warn("Number of columns support not available "
2623
"in versions of matplotlib prior to 0.98")
2724
else:

Plot.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from boomslang_exceptions import BoomslangPlotConfigurationException
1212
from boomslang_exceptions import BoomslangPlotRenderingException
1313

14-
from Utils import getGoldenRatioDimensions
14+
from Utils import getGoldenRatioDimensions, _check_min_matplotlib_version
1515

1616
class Plot(object):
1717
"""
@@ -510,15 +510,12 @@ def drawPlot(self, fig, ax):
510510
legendKeywords = {}
511511

512512
if self.legendCols > 0:
513-
versionParts = [int(x) for x in matplotlib.__version__.split('.')]
514-
515-
(superMajor, major, minor) = versionParts[0:3]
516-
517513
if self.legendBboxToAnchor is not None:
518514
legendKeywords["bbox_to_anchor"] = self.legendBboxToAnchor
519515

520-
if superMajor == 0 and major < 98:
521-
print >>sys.stderr, "Number of columns support not available in versions of matplotlib prior to 0.98"
516+
if _check_min_matplotlib_version(0, 98, 0):
517+
print >>sys.stderr, "Number of columns support not available " \
518+
"in versions of matplotlib prior to 0.98"
522519
else:
523520
legendKeywords["ncol"] = self.legendCols
524521
legendKeywords["scatterpoints"] = self.scatterPoints
@@ -530,7 +527,8 @@ def drawPlot(self, fig, ax):
530527

531528
if self.legend:
532529
if len(plotHandles) == 0:
533-
print >>sys.stderr, "ERROR: Plot wanted to draw a legend, but none of its elements have labels"
530+
print >>sys.stderr, "ERROR: Plot wanted to draw a legend, " \
531+
"but none of its elements have labels"
534532
sys.exit(1)
535533

536534
if self.twinxIndex > 0:

PlotLayout.py

+2-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import warnings
77
from boomslang_exceptions import BoomslangPlotRenderingException
88

9-
from Utils import getGoldenRatioDimensions
9+
from Utils import getGoldenRatioDimensions, _check_min_matplotlib_version
1010

1111
class PlotLayout(object):
1212
def __init__(self):
@@ -239,7 +239,7 @@ def _doPlot(self):
239239
figLegendKeywords = {}
240240

241241
if self.figLegendCols is not None:
242-
if not self._check_min_matplotlib_version((0, 98, 0)):
242+
if not self._check_min_matplotlib_version(0, 98, 0):
243243
warnings.warn("Number of columns support not available in "
244244
"versions of matplotlib prior to 0.98")
245245
else:
@@ -265,15 +265,6 @@ def _doPlot(self):
265265
def _plot_subplot(self, plot, fig, rows, cols, pos, projection):
266266
return plot.subplot(fig, rows, cols, pos, projection)
267267

268-
def _check_min_matplotlib_version(self, version):
269-
versionPieces = [int(x) for x in matplotlib.__version__.split('.')]
270-
271-
(superMajor, major, minor) = versionPieces[0:3]
272-
273-
minVersionSatisfied = (superMajor >= version[0] and major >= version[1]
274-
and minor >= version[2])
275-
return minVersionSatisfied
276-
277268
def plot(self):
278269
fig = self._doPlot()
279270
if not pylab.isinteractive():

Utils.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,12 @@ def getCDF(values):
9595

9696
return line
9797

98-
def _check_min_matplotlib_version(self, version):
99-
versionPieces = [int(x) for x in matplotlib.__version__.split('.')]
98+
def _check_min_matplotlib_version(min_super_major, min_major, min_minor):
99+
version_pieces = [int(x) for x in matplotlib.__version__.split('.')]
100100

101-
(superMajor, major, minor) = versionPieces[0:3]
101+
(super_major, major, minor) = version_pieces[0:3]
102102

103-
minVersionSatisfied = (superMajor >= version[0] and major >= version[1]
104-
and minor >= version[2])
105-
return minVersionSatisfied
103+
min_version_satisfied = (super_major >= min_super_major
104+
and major >= min_major
105+
and minor >= min_minor)
106+
return min_version_satisfied

WeightedPlotLayout.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os
66
from boomslang import PlotLayout
77

8-
from Utils import getGoldenRatioDimensions
8+
from Utils import getGoldenRatioDimensions, _check_min_matplotlib_version
99

1010
class WeightedPlotLayout(PlotLayout):
1111
def __init__(self):
@@ -169,12 +169,9 @@ def applyParams(r, pp):
169169
figLegendKeywords = {}
170170

171171
if self.figLegendCols is not None:
172-
versionPieces = [int(x) for x in matplotlib.__version__.split('.')]
173-
174-
(superMajor, major, minor) = versionPieces[0:3]
175-
176-
if superMajor == 0 and major < 98:
177-
print >>sys.stderr, "Number of columns support not available in versions of matplotlib prior to 0.98"
172+
if _check_min_matplotlib_version(0, 98, 0):
173+
print >>sys.stderr, "Number of columns support not " \
174+
"available in versions of matplotlib prior to 0.98"
178175
else:
179176
figLegendKeywords["ncol"] = self.figLegendCols
180177

0 commit comments

Comments
 (0)