diff --git a/src/tikzplotlib/_legend.py b/src/tikzplotlib/_legend.py index 29d8e635..4609f80c 100644 --- a/src/tikzplotlib/_legend.py +++ b/src/tikzplotlib/_legend.py @@ -78,8 +78,13 @@ def draw_legend(data, obj): if alignment: data["current axes"].axis_options.append(f"legend cell align={{{alignment}}}") - if obj._ncol != 1: - data["current axes"].axis_options.append(f"legend columns={obj._ncol}") + try: + ncols = obj._ncols + except AttributeError: + # backwards-compatibility with matplotlib < 3.6.0 + ncols = obj._ncol + if ncols != 1: + data["current axes"].axis_options.append(f"legend columns={ncols}") # Write styles to data if legend_style: