Skip to content

Commit cd20103

Browse files
committed
more lint
1 parent 643117a commit cd20103

File tree

4 files changed

+37
-29
lines changed

4 files changed

+37
-29
lines changed

.pylintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ disable=
55
duplicate-code,
66
fixme,
77
invalid-name,
8+
locally-disabled,
89
missing-docstring,
910
too-many-branches,
1011
too-many-statements,

matplotlib2tikz/axes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ def __init__(self, data, obj):
174174
# Unfortunately, _tickdir doesn't seem to be quite accurate. See
175175
# <https://github.com/matplotlib/matplotlib/issues/5311>.
176176
# For now, just take the first tick direction of each of the axes.
177+
# pylint: disable=protected-access
177178
x_tick_dirs = [tick._tickdir for tick in obj.xaxis.get_major_ticks()]
178179
y_tick_dirs = [tick._tickdir for tick in obj.yaxis.get_major_ticks()]
179180
if x_tick_dirs or y_tick_dirs:
@@ -225,6 +226,7 @@ def __init__(self, data, obj):
225226
# <http://sourceforge.net/p/matplotlib/mailman/message/25169234/>
226227
# Coordinate of the lines are entirely meaningless, but styles
227228
# (colors,...) are respected.
229+
# pylint: disable=protected-access
228230
if obj.xaxis._gridOnMajor:
229231
self.axis_options.append('xmajorgrids')
230232
elif obj.xaxis._gridOnMinor:
@@ -237,6 +239,7 @@ def __init__(self, data, obj):
237239
if col != 'black':
238240
self.axis_options.append('x grid style={%s}' % col)
239241

242+
# pylint: disable=protected-access
240243
if obj.yaxis._gridOnMajor:
241244
self.axis_options.append('ymajorgrids')
242245
elif obj.yaxis._gridOnMinor:
@@ -613,6 +616,7 @@ def _handle_linear_segmented_color_map(cmap):
613616
# Label the 3 elements in each row in the cdict entry for a given color as
614617
# (x, y0, y1). Then for values of x between x[i] and x[i+1] the color
615618
# value is interpolated between y1[i] and y0[i+1].
619+
# pylint: disable=protected-access
616620
segdata = cmap._segmentdata
617621
red = segdata['red']
618622
green = segdata['green']

matplotlib2tikz/legend.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ def draw_legend(data, obj):
1111
'''Adds legend code.
1212
'''
1313
texts = []
14-
childrenAlignment = []
14+
children_alignment = []
1515
for text in obj.texts:
1616
texts.append('%s' % text.get_text())
17-
childrenAlignment.append('%s' % text.get_horizontalalignment())
17+
children_alignment.append('%s' % text.get_horizontalalignment())
1818

1919
cont = 'legend entries={{%s}}' % '},{'.join(texts)
2020
data['extra axis options'].add(cont)
2121

2222
# Get the location.
2323
# http://matplotlib.org/api/legend_api.html
2424
pad = 0.03
25+
# pylint: disable=protected-access
2526
loc = obj._loc
2627
if loc == 0:
2728
# best
@@ -33,8 +34,9 @@ def draw_legend(data, obj):
3334

3435
# Rectangles of the legend and of the axes
3536
# Lower left and upper right points
36-
x0_legend, x1_legend = obj._legend_box \
37-
.get_window_extent(renderer).get_points()
37+
# pylint: disable=protected-access
38+
x0_legend, x1_legend = \
39+
obj._legend_box.get_window_extent(renderer).get_points()
3840
x0_axes, x1_axes = obj.axes.get_window_extent(renderer).get_points()
3941
dimension_legend = x1_legend - x0_legend
4042
dimension_axes = x1_axes - x0_axes
@@ -168,26 +170,27 @@ def draw_legend(data, obj):
168170
legend_style.append('fill=%s' % fill_xcolor)
169171

170172
# Get the horizontal alignment
171-
if len(childrenAlignment) > 0:
172-
alignment = childrenAlignment[0]
173-
else:
173+
try:
174+
alignment = children_alignment[0]
175+
except IndexError:
174176
alignment = None
175177

176-
for childAlignment in childrenAlignment:
177-
if alignment != childAlignment:
178+
for child_alignment in children_alignment:
179+
if alignment != child_alignment:
178180
warnings.warn(
179181
'Varying horizontal alignments in the legend. Using default.'
180182
)
181183
alignment = None
182184
break
183185

186+
if alignment:
187+
data['extra axis options'].add(
188+
'legend cell align={%s}' % alignment
189+
)
190+
184191
# Write styles to data
185192
if legend_style:
186193
style = 'legend style={%s}' % ', '.join(legend_style)
187194
data['extra axis options'].add(style)
188195

189-
if childAlignment:
190-
cellAlign = 'legend cell align={%s}' % alignment
191-
data['extra axis options'].add(cellAlign)
192-
193196
return data

matplotlib2tikz/line2d.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -212,23 +212,23 @@ def _mpl_linewidth2pgfp_linewidth(data, line_width):
212212
# ('thin').
213213
# Match the two defaults, and scale for the rest.
214214
scaled_line_width = line_width / 1.0 # scale by default line width
215-
if scaled_line_width == 0.25:
216-
return 'ultra thin'
217-
elif scaled_line_width == 0.5:
218-
return 'very thin'
219-
elif scaled_line_width == 1.0:
220-
pass # PGFPlots default line width, 'thin'
221-
elif scaled_line_width == 1.5:
222-
return 'semithick'
223-
elif scaled_line_width == 2:
224-
return 'thick'
225-
elif scaled_line_width == 3:
226-
return 'very thick'
227-
elif scaled_line_width == 4:
228-
return 'ultra thick'
229-
else:
215+
literals = {
216+
0.25: 'ultra thin',
217+
0.5: 'very thin',
218+
1.0: None, # default, 'thin'
219+
1.5: 'semithick',
220+
2: 'thick',
221+
3: 'very thick',
222+
4: 'ultra thick',
223+
}
224+
225+
try:
226+
out = literals[scaled_line_width]
227+
except KeyError:
230228
# explicit line width
231-
return 'line width=%rpt' % (0.4 * line_width)
229+
out = 'line width=%rpt' % (0.4 * line_width)
230+
231+
return out
232232

233233

234234
# for matplotlib markers, see: http://matplotlib.org/api/markers_api.html

0 commit comments

Comments
 (0)