Skip to content

Commit 5e3e283

Browse files
author
John McCulough
committed
Modified WeightPlotLayout to mimick PlotLayout behavior when weights are 1 (apart from column grouping). Also changed __doPlot to _doPlot to avoid the special semantics of the '__'
1 parent 991d45f commit 5e3e283

File tree

3 files changed

+20
-43
lines changed

3 files changed

+20
-43
lines changed

PlotLayout.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from Utils import getGoldenRatioDimensions
88

9-
class PlotLayout:
9+
class PlotLayout(object):
1010
def __init__(self):
1111
self.groupedPlots = {}
1212
self.plots = []
@@ -99,7 +99,7 @@ def setPlotParameters(self, **kwdict):
9999
self.plotParams["hspace"] = 0.20
100100

101101

102-
def __doPlot(self):
102+
def _doPlot(self):
103103
if len(self.groupedPlots) + len(self.plots) == 0:
104104
print "PlotLayout.plot(): No data to plot!"
105105
return
@@ -245,22 +245,22 @@ def __doPlot(self):
245245
hspace=self.plotParams["hspace"])
246246

247247
def plot(self):
248-
self.__doPlot()
248+
self._doPlot()
249249
if not pylab.isinteractive():
250250
pylab.show()
251251
else:
252252
pylab.draw()
253253

254254
def save(self, filename):
255+
print self.__class__
255256
print "Saving %s ..." % filename
256257

257258
tempDisplayHack = False
258259

259260
if "DISPLAY" not in os.environ:
260261
tempDisplayHack = True
261262
os.environ["DISPLAY"] = ":0.0"
262-
263-
self.__doPlot()
263+
self._doPlot()
264264
pylab.savefig(filename)
265265
pylab.clf()
266266

WeightedPlotLayout.py

+14-33
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99

1010
class WeightedPlotLayout(PlotLayout):
1111
def __init__(self):
12-
PlotLayout.__init__(self)
12+
super(WeightedPlotLayout,self).__init__()
1313
self.groupedWeights = {}
1414
self.weights = []
1515

1616
def addPlot(self, plot, grouping=None, weight=1):
17-
PlotLayout.addPlot(self, plot, grouping=grouping)
17+
super(WeightedPlotLayout,self).addPlot(plot, grouping=grouping)
1818

1919
if grouping == None:
2020
self.weights.append(weight)
@@ -23,9 +23,9 @@ def addPlot(self, plot, grouping=None, weight=1):
2323
self.groupedWeights[grouping] = []
2424
self.groupedWeights[grouping].append(weight)
2525

26-
def __doPlot(self):
26+
def _doPlot(self):
2727
if len(self.groupedPlots) + len(self.plots) == 0:
28-
print "PlotLayout.plot(): No data to plot!"
28+
print "WeightedPlotLayout.plot(): No data to plot!"
2929
return
3030

3131
if self.rcParams is not None:
@@ -68,11 +68,13 @@ def __doPlot(self):
6868
figTop = self.plotParams["top"]
6969
figLeft = self.plotParams["left"]
7070

71-
hgap = self.plotParams["hspace"] / (numRows - 1)
7271
wspace = self.plotParams["wspace"]
72+
hspace = self.plotParams["hspace"]
7373

7474
height = figTop - self.plotParams["bottom"]
75-
rowHeight = (height - self.plotParams["hspace"]) / numRows
75+
rowHeight = height / (numRows + (numRows - 1) * hspace)
76+
hgap = self.plotParams["hspace"] * rowHeight
77+
7678
rowWidth = self.plotParams["right"] - figLeft
7779

7880
# To contain a list of plots and rects, so we can do the
@@ -88,7 +90,11 @@ def __doPlot(self):
8890
totalWeight = 1.0 * sum(weights)
8991
numPlots = len(plots)
9092

91-
availableWidth = rowWidth - wspace
93+
# hspace, wspace behavior defined in matplotlib/axes.py
94+
# in the class SubplotBase
95+
unitWidth = rowWidth / (numPlots + (numPlots-1) * wspace)
96+
availableWidth = unitWidth * numPlots
97+
wgap = unitWidth * wspace
9298

9399
bottom = figTop - rowHeight - (rowHeight + hgap) * currentRow
94100
left = figLeft
@@ -100,7 +106,7 @@ def __doPlot(self):
100106

101107
plotInfo.append((plot, [left, bottom, myWidth, rowHeight]))
102108

103-
left += myWidth + wspace / (numPlots - 1)
109+
left += myWidth + wgap
104110

105111
currentRow += 1
106112

@@ -145,28 +151,3 @@ def __doPlot(self):
145151
pylab.figlegend(plotHandles, plotLabels,
146152
self.figLegendLoc,
147153
**figLegendKeywords)
148-
149-
# For some reason the wrong __doPlot gets called unless these are
150-
# here?
151-
def plot(self):
152-
self.__doPlot()
153-
if not pylab.isinteractive():
154-
pylab.show()
155-
else:
156-
pylab.draw()
157-
158-
def save(self, filename):
159-
print "Saving %s ..." % filename
160-
161-
tempDisplayHack = False
162-
163-
if "DISPLAY" not in os.environ:
164-
tempDisplayHack = True
165-
os.environ["DISPLAY"] = ":0.0"
166-
167-
self.__doPlot()
168-
pylab.savefig(filename)
169-
pylab.clf()
170-
171-
if tempDisplayHack == True:
172-
del os.environ["DISPLAY"]

examples/weightedlayout.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,5 @@
5050

5151
# Set values similar to those given in the "Configure subplots" sliders in the
5252
# interactive figure
53-
layout.setFigureDimensions(8,4.9)
54-
layout.setAxesLabelSize(10)
55-
layout.setXTickLabelSize(10)
56-
layout.setYTickLabelSize(10)
57-
layout.setPlotParameters(wspace=0.1)
53+
layout.setPlotParameters(hspace=0.48)
5854
layout.save("weightedlayout.png")

0 commit comments

Comments
 (0)