Skip to content

Commit 7404b39

Browse files
committed
increase allowed complexity from 18 to 20
1 parent cfdf1ec commit 7404b39

File tree

2 files changed

+34
-38
lines changed

2 files changed

+34
-38
lines changed

.flake8

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[flake8]
22
ignore = E203, E266, E501, W503
33
max-line-length = 80
4-
max-complexity = 18
4+
max-complexity = 20
55
select = B,C,E,F,W,T4,B9

matplotlib2tikz/axes.py

+33-37
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,7 @@ def __init__(self, data, obj):
2424
self.is_subplot = False
2525

2626
if isinstance(obj, mpl.axes.Subplot):
27-
# https://github.com/matplotlib/matplotlib/issues/7225#issuecomment-252173667
28-
geom = obj.get_subplotspec().get_topmost_subplotspec().get_geometry()
29-
30-
self.nsubplots = geom[0] * geom[1]
31-
if self.nsubplots > 1:
32-
# Is this an axis-colorbar pair? No need for groupplot then.
33-
is_groupplot = self.nsubplots != 2 or not _find_associated_colorbar(obj)
34-
35-
if is_groupplot:
36-
self.is_subplot = True
37-
# subplotspec geometry positioning is 0-based
38-
self.subplot_index = geom[2] + 1
39-
if (
40-
"is_in_groupplot_env" not in data
41-
or not data["is_in_groupplot_env"]
42-
):
43-
self.content.append(
44-
"\\begin{groupplot}[group style="
45-
"{group size=%.d by %.d}]\n" % (geom[1], geom[0])
46-
)
47-
data["is_in_groupplot_env"] = True
48-
data["pgfplots libs"].add("groupplots")
27+
self._subplot(obj, data)
4928

5029
self.axis_options = []
5130

@@ -57,15 +36,15 @@ def __init__(self, data, obj):
5736
# get plot title
5837
title = obj.get_title()
5938
if title:
60-
self.axis_options.append("title={" + title + "}")
39+
self.axis_options.append("title={{{}}}".format(title))
6140

6241
# get axes titles
6342
xlabel = obj.get_xlabel()
6443
if xlabel:
65-
self.axis_options.append("xlabel={" + xlabel + "}")
44+
self.axis_options.append("xlabel={{{}}}".format(xlabel))
6645
ylabel = obj.get_ylabel()
6746
if ylabel:
68-
self.axis_options.append("ylabel={" + ylabel + "}")
47+
self.axis_options.append("ylabel={{{}}}".format(ylabel))
6948

7049
# Axes limits.
7150
# Sort the limits so make sure that the smaller of the two is actually
@@ -97,19 +76,13 @@ def __init__(self, data, obj):
9776

9877
# axis positions
9978
xaxis_pos = obj.get_xaxis().label_position
100-
if xaxis_pos == "bottom":
101-
# this is the default
102-
pass
103-
else:
104-
assert xaxis_pos == "top"
79+
if xaxis_pos == "top":
80+
# default: "bottom"
10581
self.axis_options.append("axis x line=top")
10682

10783
yaxis_pos = obj.get_yaxis().label_position
108-
if yaxis_pos == "left":
109-
# this is the default
110-
pass
111-
else:
112-
assert yaxis_pos == "right"
84+
if yaxis_pos == "right":
85+
# default: "left"
11386
self.axis_options.append("axis y line=right")
11487

11588
self._ticks(data, obj)
@@ -121,7 +94,7 @@ def __init__(self, data, obj):
12194
axcol = obj.spines["bottom"].get_edgecolor()
12295
data, col, _ = color.mpl_color2xcolor(data, axcol)
12396
if col != "black":
124-
self.axis_options.append("axis line style={%s}" % col)
97+
self.axis_options.append("axis line style={{{}}}".format(col))
12598

12699
# background color
127100
try:
@@ -133,7 +106,7 @@ def __init__(self, data, obj):
133106

134107
data, col, _ = color.mpl_color2xcolor(data, bgcolor)
135108
if col != "white":
136-
self.axis_options.append("axis background/.style={fill=%s}" % col)
109+
self.axis_options.append("axis background/.style={{fill={}}}".format(col))
137110

138111
# find color bar
139112
colorbar = _find_associated_colorbar(obj)
@@ -404,6 +377,29 @@ def _colorbar(self, colorbar, data):
404377

405378
return
406379

380+
def _subplot(self, obj, data):
381+
# https://github.com/matplotlib/matplotlib/issues/7225#issuecomment-252173667
382+
geom = obj.get_subplotspec().get_topmost_subplotspec().get_geometry()
383+
384+
self.nsubplots = geom[0] * geom[1]
385+
if self.nsubplots > 1:
386+
# Is this an axis-colorbar pair? No need for groupplot then.
387+
is_groupplot = self.nsubplots != 2 or not _find_associated_colorbar(obj)
388+
389+
if is_groupplot:
390+
self.is_subplot = True
391+
# subplotspec geometry positioning is 0-based
392+
self.subplot_index = geom[2] + 1
393+
if "is_in_groupplot_env" not in data or not data["is_in_groupplot_env"]:
394+
self.content.append(
395+
"\\begin{groupplot}[group style="
396+
"{group size=%.d by %.d}]\n" % (geom[1], geom[0])
397+
)
398+
data["is_in_groupplot_env"] = True
399+
data["pgfplots libs"].add("groupplots")
400+
401+
return
402+
407403

408404
def _get_label_rotation_and_horizontal_alignment(obj, data, axes_obj):
409405
tick_label_text_width = None

0 commit comments

Comments
 (0)