Skip to content

Commit ad7d033

Browse files
author
alexras
committed
Check version before putting columns in legend.
1 parent a662756 commit ad7d033

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

Plot.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,22 @@ def drawPlot(self, ax):
395395
if self.yLabel is not None:
396396
ax.set_ylabel(self.yLabel)
397397

398+
legendKeywords = {}
399+
400+
if self.legendCols > 0:
401+
(superMajor, major, minor) = [int(x) for x in matplotlib.__version__.split('.')]
402+
403+
if superMajor == 0 and major < 98:
404+
print >>sys.stderr, "Number of columns support not available in versions of matplotlib prior to 0.98"
405+
else:
406+
legendKeywords["ncol"] = self.legendCols
407+
408+
398409
if self.legend:
399410
pylab.legend(plotHandles, plotLabels, loc=self.legendLoc,
400-
ncol=self.legendCols)
411+
**legendKeywords)
401412
if self.figLegend:
402413
pylab.figlegend(plotHandles, plotLabels, loc=self.legendLoc,
403-
ncol=self.legendCols)
414+
**legendKeywords)
404415

405416
return (plotHandles, plotLabels)

PlotLayout.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pylab
2+
import matplotlib
23
from matplotlib import pyplot
34
import sys
45

@@ -218,9 +219,19 @@ def __doPlot(self):
218219
ungroupedPlotsRemaining -= 1
219220

220221
if self.figLegendLoc is not None:
222+
figLegendKeywords = {}
223+
224+
if self.figLegendCols is not None:
225+
(superMajor, major, minor) = [int(x) for x in matplotlib.__version__.split('.')]
226+
227+
if superMajor == 0 and major < 98:
228+
print >>sys.stderr, "Number of columns support not available in versions of matplotlib prior to 0.98"
229+
else:
230+
figLegendKeywords["ncol"] = self.figLegendCols
231+
221232
pylab.figlegend(plotHandles, plotLabels,
222233
self.figLegendLoc,
223-
ncol=self.figLegendCols)
234+
**figLegendKeywords)
224235

225236
if self.plotParams is not None:
226237
pylab.subplots_adjust(left=self.plotParams["left"],

0 commit comments

Comments
 (0)