Skip to content

Commit 54f64d4

Browse files
authored
Merge pull request #125 from nschloe/open-groupplot
Open groupplot
2 parents b72afd4 + c149e7d commit 54f64d4

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

matplotlib2tikz/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
__copyright__ = 'Copyright (c) 2010-2016, %s <%s>' % (__author__, __email__)
99
__credits__ = []
1010
__license__ = 'MIT License'
11-
__version__ = '0.5.15'
11+
__version__ = '0.5.16'
1212
__maintainer__ = 'Nico Schlömer'
1313
__status__ = 'Production'
1414

matplotlib2tikz/axes.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ def __init__(self, data, obj):
4141
self.is_subplot = True
4242
# subplotspec geometry positioning is 0-based
4343
self.subplot_index = geom[2] + 1
44-
if self.subplot_index == 1:
44+
if 'is_in_groupplot_env' not in data \
45+
or not data['is_in_groupplot_env']:
4546
self.content.append(
4647
'\\begin{groupplot}[group style='
4748
'{group size=%.d by %.d}]\n' % (geom[1], geom[0])
4849
)
50+
data['is_in_groupplot_env'] = True
4951
data['pgfplots libs'].add('groupplots')
5052

5153
self.axis_options = []
@@ -358,10 +360,11 @@ def get_begin_code(self):
358360
content.append('[\n' + ',\n'.join(self.axis_options) + '\n]\n')
359361
return content
360362

361-
def get_end_code(self):
363+
def get_end_code(self, data):
362364
if not self.is_subplot:
363365
return '\\end{axis}\n\n'
364366
elif self.is_subplot and self.nsubplots == self.subplot_index:
367+
data['is_in_groupplot_env'] = False
365368
return '\\end{groupplot}\n\n'
366369
else:
367370
return ''

matplotlib2tikz/save.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ def save(filepath,
145145
# gather the file content
146146
data, content = _recurse(data, figure)
147147

148+
# Check if there is still an open groupplot environment. This occurs if not
149+
# all of the group plot slots are used.
150+
if 'is_in_groupplot_env' in data and data['is_in_groupplot_env']:
151+
content.extend('\\end{groupplot}\n\n')
152+
148153
disclaimer = 'This file was created by matplotlib2tikz v%s.' % __version__
149154

150155
# write disclaimer to the file header
@@ -225,15 +230,15 @@ def _recurse(data, obj):
225230

226231
ax = axes.Axes(data, child)
227232
if not ax.is_colorbar:
228-
# Run through the children objects, gather the content.
233+
# Run through the child objects, gather the content.
229234
data, children_content = _recurse(data, child)
230235
# add extra axis options from children
231236
if data['extra axis options']:
232237
ax.axis_options.extend(data['extra axis options'])
233238
# populate content
234239
content.extend(ax.get_begin_code())
235240
content.extend(children_content)
236-
content.extend(ax.get_end_code())
241+
content.extend(ax.get_end_code(data))
237242
elif isinstance(child, mpl.lines.Line2D):
238243
data, cont = line2d.draw_line2d(data, child)
239244
content.extend(cont)

0 commit comments

Comments
 (0)