Skip to content

Commit 30e48fc

Browse files
authored
Merge pull request #182 from nschloe/legend-columns
Legend columns
2 parents 5dd1a27 + 5ee906b commit 30e48fc

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

matplotlib2tikz/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
__copyright__ = 'Copyright (c) 2010-2017, %s <%s>' % (__author__, __email__)
66
__credits__ = []
77
__license__ = 'License :: OSI Approved :: MIT License'
8-
__version__ = '0.6.10'
8+
__version__ = '0.6.11'
99
__maintainer__ = u'Nico Schlömer'
1010
__status__ = 'Development Status :: 5 - Production/Stable'

matplotlib2tikz/legend.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,18 @@ def draw_legend(data, obj):
179179
if alignment != child_alignment:
180180
warnings.warn(
181181
'Varying horizontal alignments in the legend. Using default.'
182-
)
182+
)
183183
alignment = None
184184
break
185185

186186
if alignment:
187187
data['extra axis options'].add(
188-
'legend cell align={%s}' % alignment
188+
'legend cell align={{{}}}'.format(alignment)
189+
)
190+
191+
if obj._ncol != 1:
192+
data['extra axis options'].add(
193+
'legend columns={}'.format(obj._ncol)
189194
)
190195

191196
# Write styles to data

test/test_legend_columns.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
import helpers
4+
5+
6+
def plot():
7+
import numpy as np
8+
import matplotlib.pyplot as plt
9+
fig, ax = plt.subplots(figsize=(17, 6))
10+
ax.plot(np.array([1, 5]), label='Test 1')
11+
ax.plot(np.array([5, 1]), label='Test 2')
12+
ax.legend(ncol=2, loc='upper center')
13+
return fig
14+
15+
16+
def test():
17+
phash = helpers.Phash(plot())
18+
assert phash.phash == '8386de99666939a9', phash.get_details()
19+
return
20+
21+
22+
if __name__ == '__main__':
23+
helpers.compare_with_latex(plot())

0 commit comments

Comments
 (0)