9
9
10
10
class WeightedPlotLayout (PlotLayout ):
11
11
def __init__ (self ):
12
- PlotLayout .__init__ (self )
12
+ super ( WeightedPlotLayout , self ) .__init__ ()
13
13
self .groupedWeights = {}
14
14
self .weights = []
15
15
16
16
def addPlot (self , plot , grouping = None , weight = 1 ):
17
- PlotLayout .addPlot (self , plot , grouping = grouping )
17
+ super ( WeightedPlotLayout , self ) .addPlot (plot , grouping = grouping )
18
18
19
19
if grouping == None :
20
20
self .weights .append (weight )
@@ -23,9 +23,9 @@ def addPlot(self, plot, grouping=None, weight=1):
23
23
self .groupedWeights [grouping ] = []
24
24
self .groupedWeights [grouping ].append (weight )
25
25
26
- def __doPlot (self ):
26
+ def _doPlot (self ):
27
27
if len (self .groupedPlots ) + len (self .plots ) == 0 :
28
- print "PlotLayout .plot(): No data to plot!"
28
+ print "WeightedPlotLayout .plot(): No data to plot!"
29
29
return
30
30
31
31
if self .rcParams is not None :
@@ -68,11 +68,13 @@ def __doPlot(self):
68
68
figTop = self .plotParams ["top" ]
69
69
figLeft = self .plotParams ["left" ]
70
70
71
- hgap = self .plotParams ["hspace" ] / (numRows - 1 )
72
71
wspace = self .plotParams ["wspace" ]
72
+ hspace = self .plotParams ["hspace" ]
73
73
74
74
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
+
76
78
rowWidth = self .plotParams ["right" ] - figLeft
77
79
78
80
# To contain a list of plots and rects, so we can do the
@@ -88,7 +90,11 @@ def __doPlot(self):
88
90
totalWeight = 1.0 * sum (weights )
89
91
numPlots = len (plots )
90
92
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
92
98
93
99
bottom = figTop - rowHeight - (rowHeight + hgap ) * currentRow
94
100
left = figLeft
@@ -100,7 +106,7 @@ def __doPlot(self):
100
106
101
107
plotInfo .append ((plot , [left , bottom , myWidth , rowHeight ]))
102
108
103
- left += myWidth + wspace / ( numPlots - 1 )
109
+ left += myWidth + wgap
104
110
105
111
currentRow += 1
106
112
@@ -145,28 +151,3 @@ def __doPlot(self):
145
151
pylab .figlegend (plotHandles , plotLabels ,
146
152
self .figLegendLoc ,
147
153
** 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" ]
0 commit comments