Skip to content

Commit 7077905

Browse files
committed
handle legend columns
1 parent b719b7b commit 7077905

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ def plot():
77
import numpy as np
88
import matplotlib.pyplot as plt
99
fig, ax = plt.subplots(figsize=(17, 6))
10-
ax.plot(np.array([1, 2, 3, 4, 5]), label='Test 1')
11-
ax.plot(np.array([5, 4, 3, 2, 1]), label='Test 2')
10+
ax.plot(np.array([1, 5]), label='Test 1')
11+
ax.plot(np.array([5, 1]), label='Test 2')
1212
ax.legend(ncol=2, loc='upper center')
1313
return fig
1414

1515

1616
def test():
1717
phash = helpers.Phash(plot())
18-
assert phash.phash == 'a3267e19cad99998', phash.get_details()
18+
assert phash.phash == '8386de99666939a9', phash.get_details()
1919
return
2020

2121

0 commit comments

Comments
 (0)