Skip to content

Commit 6010b5d

Browse files
committed
more lints
1 parent fb8aae0 commit 6010b5d

File tree

7 files changed

+59
-37
lines changed

7 files changed

+59
-37
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ before_install:
3535
# Make sure to put the readme test at the very end; otherwise it's messing
3636
# around with the other tests.
3737
- code_extract README.md test/zzz_readme_test.py --filter python,test
38-
- pylint matplotlib2tikz
3938

4039
install:
4140
- pip install -r test_requirements.txt
@@ -52,6 +51,7 @@ before_script:
5251

5352
# run tests
5453
script:
54+
- pylint matplotlib2tikz
5555
# cd into test directory to make sure we're using the pip-installed
5656
# matplotlib2tikz.
5757
- cd test && MPLBACKEND=Agg pytest --cov matplotlib2tikz

matplotlib2tikz/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#
33
'''Script to convert Matplotlib generated figures into TikZ/PGFPlots figures.
44
'''
5+
from __future__ import print_function
56

67
from matplotlib2tikz.__about__ import (
78
__author__,

matplotlib2tikz/axes.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,8 @@ def get_end_code(self, data):
399399
elif self.is_subplot and self.nsubplots == self.subplot_index:
400400
data['is_in_groupplot_env'] = False
401401
return '\\end{groupplot}\n\n'
402-
else:
403-
return ''
402+
403+
return ''
404404

405405

406406
def _get_label_rotation_and_horizontal_alignment(
@@ -421,7 +421,7 @@ def _get_label_rotation_and_horizontal_alignment(
421421
obj.xaxis.get_majorticklabels() if axes_obj == 'x' \
422422
else obj.yaxis.get_majorticklabels()
423423

424-
if len(major_tick_labels) == 0:
424+
if not major_tick_labels:
425425
return None
426426

427427
tick_labels_rotation = \
@@ -448,7 +448,7 @@ def _get_label_rotation_and_horizontal_alignment(
448448
'label text width\' has been passed in the \'extra\' '
449449
'parameter' % axes_obj)
450450

451-
if len(values) > 0:
451+
if values:
452452
label_style = \
453453
'%sticklabel style = {%s}' % (axes_obj, ','.join(values))
454454
else:
@@ -733,16 +733,16 @@ def _handle_listed_color_map(cmap):
733733
if cmap.N is None or cmap.N == len(cmap.colors):
734734
colors = [
735735
'rgb(%d%s)=(%.15g,%.15g,%.15g)'
736-
% (k, unit, color[0], color[1], color[2])
737-
for (k, color) in enumerate(cmap.colors)
736+
% (k, unit, rgb[0], rgb[1], rgb[2])
737+
for (k, rgb) in enumerate(cmap.colors)
738738
]
739739
else:
740740
reps = int(float(cmap.N) / len(cmap.colors) - 0.5) + 1
741741
repeated_cols = reps * cmap.colors
742742
colors = [
743743
'rgb(%d%s)=(%.15g,%.15g,%.15g)'
744-
% (k, unit, color[0], color[1], color[2])
745-
for (k, color) in enumerate(repeated_cols[:cmap.N])
744+
% (k, unit, rgb[0], rgb[1], rgb[2])
745+
for (k, rgb) in enumerate(repeated_cols[:cmap.N])
746746
]
747747

748748
colormap_string = '{mymap}{[1%s]\n %s\n}' % \

matplotlib2tikz/line2d.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# -*- coding: utf-8 -*-
22
#
3+
from __future__ import print_function
4+
35
import six
46

57
from . import color as mycol
@@ -15,6 +17,7 @@ def draw_line2d(data, obj):
1517
# If line is of length 0, do nothing. Otherwise, an empty \addplot table
1618
# will be created, which will be interpreted as an external data source
1719
# in either the file '' or '.tex'. Instead, render nothing.
20+
# pylint: disable=len-as-condition
1821
if len(obj.get_xdata()) == 0:
1922
return data, []
2023

matplotlib2tikz/patch.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,28 @@ def draw_patch(data, obj):
2121
elif isinstance(obj, mpl.patches.Ellipse):
2222
# ellipse specialization
2323
return _draw_ellipse(data, obj, draw_options)
24-
else:
25-
# regular patch
26-
return mypath.draw_path(
27-
data, obj.get_path(), draw_options=draw_options
28-
)
24+
25+
# regular patch
26+
return mypath.draw_path(
27+
data, obj.get_path(), draw_options=draw_options
28+
)
2929

3030

3131
def draw_patchcollection(data, obj):
3232
'''Returns PGFPlots code for a number of patch objects.
3333
'''
3434
content = []
3535
# Gather the draw options.
36-
edge_colors = obj.get_edgecolor()
37-
edge_color = None if len(edge_colors) == 0 else edge_colors[0]
38-
face_colors = obj.get_facecolor()
39-
face_color = None if len(face_colors) == 0 else face_colors[0]
36+
try:
37+
edge_color = obj.get_edgecolor()[0]
38+
except IndexError:
39+
edge_color = None
40+
41+
try:
42+
face_color = obj.get_facecolor()[0]
43+
except IndexError:
44+
face_color = None
45+
4046
data, draw_options = mypath.get_draw_options(
4147
data, edge_color, face_color
4248
)

matplotlib2tikz/save.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# -*- coding: utf-8 -*-
22
#
3+
from __future__ import print_function
4+
35
import codecs
46
import os
57
import matplotlib as mpl
@@ -290,8 +292,13 @@ def _recurse(data, obj):
290292
elif isinstance(child, mpl.patches.Patch):
291293
data, cont = patch.draw_patch(data, child)
292294
content.extend(cont, child.get_zorder())
293-
elif isinstance(child, mpl.collections.PatchCollection) or \
294-
isinstance(child, mpl.collections.PolyCollection):
295+
elif isinstance(
296+
child,
297+
(
298+
mpl.collections.PatchCollection,
299+
mpl.collections.PolyCollection
300+
)
301+
):
295302
data, cont = patch.draw_patchcollection(data, child)
296303
content.extend(cont, child.get_zorder())
297304
elif isinstance(child, mpl.collections.PathCollection):
@@ -305,16 +312,18 @@ def _recurse(data, obj):
305312
content.extend(cont, child.get_zorder())
306313
elif isinstance(child, mpl.legend.Legend):
307314
data = legend.draw_legend(data, child)
308-
elif isinstance(child, mpl.axis.XAxis) or \
309-
isinstance(child, mpl.axis.YAxis) or \
310-
isinstance(child, mpl.spines.Spine) or \
311-
isinstance(child, mpl.text.Text):
315+
elif isinstance(
316+
child,
317+
(
318+
mpl.axis.XAxis, mpl.axis.YAxis,
319+
mpl.spines.Spine, mpl.text.Text
320+
)):
312321
pass
313322
else:
314323
print('matplotlib2tikz: Don''t know how to handle object ''%s''.' %
315324
type(child))
316325
# XXX: This is ugly
317-
if isinstance(obj, mpl.axes.Subplot) or isinstance(obj, mpl.figure.Figure):
326+
if isinstance(obj, (mpl.axes.Subplot, mpl.figure.Figure)):
318327
for text in obj.texts:
319328
data, cont = mytext.draw_text(data, text)
320329
content.extend(cont, text.get_zorder())

matplotlib2tikz/text.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,18 @@ def _transform_positioning(ha, va):
189189
Not quite accurate but the results are equivalent more or less.'''
190190
if ha == 'center' and va == 'center':
191191
return None
192-
else:
193-
ha_mpl_to_tikz = {'right': 'east',
194-
'left': 'west',
195-
'center': ''
196-
}
197-
va_mpl_to_tikz = {'top': 'north',
198-
'bottom': 'south',
199-
'center': '',
200-
'baseline': 'base'
201-
}
202-
return ('anchor=%s %s' % (va_mpl_to_tikz[va], ha_mpl_to_tikz[ha])
203-
).strip()
192+
193+
ha_mpl_to_tikz = {
194+
'right': 'east',
195+
'left': 'west',
196+
'center': ''
197+
}
198+
va_mpl_to_tikz = {
199+
'top': 'north',
200+
'bottom': 'south',
201+
'center': '',
202+
'baseline': 'base'
203+
}
204+
return (
205+
'anchor=%s %s' % (va_mpl_to_tikz[va], ha_mpl_to_tikz[ha])
206+
).strip()

0 commit comments

Comments
 (0)