Skip to content

Commit 643117a

Browse files
committed
various lint fixes
1 parent f2dda97 commit 643117a

File tree

10 files changed

+72
-67
lines changed

10 files changed

+72
-67
lines changed

.pylintrc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
[MESSAGES CONTROL]
22

33
disable=
4-
invalid-name,
5-
missing-docstring,
64
bad-continuation,
75
duplicate-code,
86
fixme,
7+
invalid-name,
8+
missing-docstring,
9+
too-many-branches,
10+
too-many-statements,
11+
too-many-arguments,
12+
too-many-locals

matplotlib2tikz/axes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# -*- coding: utf-8 -*-
22
#
3-
from . import color
4-
53
import matplotlib as mpl
64
import numpy
75

6+
from . import color
7+
88

99
class Axes(object):
1010
def __init__(self, data, obj):
@@ -450,7 +450,7 @@ def __get_label_rotation_and_horizontal_alignment(self, obj, data, axes):
450450
% (axes, idx, x)
451451

452452
values.append(
453-
'align=\pgfkeysvalueof{/pgfplots/'
453+
'align=\\pgfkeysvalueof{/pgfplots/'
454454
'%s_tick_label_ha_\\ticknum}' % axes)
455455
values.append('text width=%s' % tick_label_text_width)
456456
else:

matplotlib2tikz/color.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def mpl_color2xcolor(data, matplotlib_color):
1717
'red': numpy.array([1, 0, 0]),
1818
'green': numpy.array([0, 1, 0]),
1919
'blue': numpy.array([0, 0, 1]),
20-
'brown': numpy.array([0.75, 0.5, 0.25]),
20+
'brown': numpy.array([0.75, 0.5, 0.25]),
2121
'lime': numpy.array([0.75, 1, 0]),
2222
'orange': numpy.array([1, 0.5, 0]),
2323
'pink': numpy.array([1, 0.75, 0.75]),
@@ -60,7 +60,7 @@ def mpl_color2xcolor(data, matplotlib_color):
6060

6161
# The cases 0.0 (my_col == black) and 1.0 (my_col == rgb) are
6262
# already accounted for by checking in available_colors above.
63-
if all(my_col[:3] == alpha * rgb) and 0.0 < alpha and alpha < 1.0:
63+
if all(my_col[:3] == alpha * rgb) and 0.0 < alpha < 1.0:
6464
xcol = name + ('!%r!black' % (alpha * 100))
6565
return data, xcol, my_col
6666

matplotlib2tikz/image.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# -*- coding: utf-8 -*-
22
#
3+
import os
4+
35
import matplotlib as mpl
46
import numpy
5-
import os
67
import PIL
78

89

@@ -30,14 +31,14 @@ def draw_image(data, obj):
3031
dims = img_array.shape
3132
if len(dims) == 2: # the values are given as one real number: look at cmap
3233
clims = obj.get_clim()
33-
34-
mpl.pyplot.imsave(fname=filename,
35-
arr=img_array,
36-
cmap=obj.get_cmap(),
37-
vmin=clims[0],
38-
vmax=clims[1],
39-
origin=obj.origin
40-
)
34+
mpl.pyplot.imsave(
35+
fname=filename,
36+
arr=img_array,
37+
cmap=obj.get_cmap(),
38+
vmin=clims[0],
39+
vmax=clims[1],
40+
origin=obj.origin
41+
)
4142
else:
4243
# RGB (+alpha) information at each point
4344
assert len(dims) == 3 and dims[2] in [3, 4]
@@ -54,19 +55,17 @@ def draw_image(data, obj):
5455
if isinstance(extent, list): # convert to () list
5556
extent = tuple(extent)
5657

58+
rel_filepath = os.path.basename(filename)
5759
if data['rel data path']:
58-
rel_filepath = os.path.join(data['rel data path'],
59-
os.path.basename(filename)
60-
)
61-
else:
62-
rel_filepath = os.path.basename(filename)
60+
rel_filepath = os.path.join(data['rel data path'], rel_filepath)
6361

6462
# Explicitly use \pgfimage as includegrapics command, as the default
6563
# \includegraphics fails unexpectedly in some cases
66-
content.append('\\addplot graphics [includegraphics cmd=\pgfimage,'
67-
'xmin=%.15g, xmax=%.15g, '
68-
'ymin=%.15g, ymax=%.15g] {%s};\n'
69-
% (extent + (rel_filepath,))
70-
)
64+
content.append(
65+
'\\addplot graphics [includegraphics cmd=\\pgfimage,'
66+
'xmin=%.15g, xmax=%.15g, '
67+
'ymin=%.15g, ymax=%.15g] {%s};\n'
68+
% (extent + (rel_filepath,))
69+
)
7170

7271
return data, content

matplotlib2tikz/line2d.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# -*- coding: utf-8 -*-
22
#
3+
import six
4+
35
from . import color as mycol
46
from . import path as mypath
57

6-
import six
7-
88

99
def draw_line2d(data, obj):
1010
'''Returns the PGFPlots code for an Line2D environment.
@@ -142,9 +142,7 @@ def draw_linecollection(data, obj):
142142
linewidths = obj.get_linewidths()
143143
paths = obj.get_paths()
144144

145-
for i in range(len(paths)):
146-
path = paths[i]
147-
145+
for i, path in enumerate(paths):
148146
if i < len(edgecolors):
149147
color = edgecolors[i]
150148
else:

matplotlib2tikz/patch.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# -*- coding: utf-8 -*-
22
#
3-
from . import path as mypath
4-
53
import matplotlib as mpl
64

5+
from . import path as mypath
6+
77

88
def draw_patch(data, obj):
99
'''Return the PGFPlots code for patches.
@@ -81,7 +81,7 @@ def _draw_rectangle(data, obj, draw_options):
8181

8282
left_lower_x = obj.get_x()
8383
left_lower_y = obj.get_y()
84-
cont = ('%s\draw[%s] (axis cs:%.15g,%.15g) '
84+
cont = ('%s\\draw[%s] (axis cs:%.15g,%.15g) '
8585
'rectangle (axis cs:%.15g,%.15g);\n'
8686
) % (legend,
8787
','.join(draw_options),
@@ -100,7 +100,7 @@ def _draw_ellipse(data, obj, draw_options):
100100
# circle specialization
101101
return _draw_circle(data, obj, draw_options)
102102
x, y = obj.center
103-
cont = '\draw[%s] (axis cs:%.15g,%.15g) ellipse (%.15g and %.15g);\n' % \
103+
cont = '\\draw[%s] (axis cs:%.15g,%.15g) ellipse (%.15g and %.15g);\n' % \
104104
(','.join(draw_options),
105105
x, y,
106106
0.5 * obj.width, 0.5 * obj.height
@@ -112,7 +112,7 @@ def _draw_circle(data, obj, draw_options):
112112
'''Return the PGFPlots code for circles.
113113
'''
114114
x, y = obj.center
115-
cont = '\draw[%s] (axis cs:%.15g,%.15g) circle (%.15g);\n' % \
115+
cont = '\\draw[%s] (axis cs:%.15g,%.15g) circle (%.15g);\n' % \
116116
(','.join(draw_options),
117117
x, y,
118118
obj.get_radius()

matplotlib2tikz/path.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# -*- coding: utf-8 -*-
22
#
3-
from . import color
4-
from .axes import _mpl_cmap2pgf_cmap
5-
63
import matplotlib as mpl
74
import numpy
85

6+
from . import color
7+
from .axes import _mpl_cmap2pgf_cmap
8+
99

1010
def draw_path(obj, data, path, draw_options=None, simplify=None):
1111
'''Adds code for drawing an ordinary path in PGFPlots (TikZ).
@@ -141,9 +141,9 @@ def draw_pathcollection(data, obj):
141141
labels.append('sizedata' + 14*' ')
142142
draw_options.extend([
143143
'visualization depends on='
144-
'{\\thisrow{sizedata} \\as\perpointmarksize}',
144+
'{\\thisrow{sizedata} \\as\\perpointmarksize}',
145145
'scatter/@pre marker code/.append style='
146-
'{/tikz/mark size=\perpointmarksize}',
146+
'{/tikz/mark size=\\perpointmarksize}',
147147
])
148148

149149
if draw_options:

matplotlib2tikz/quadmesh.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ def draw_quadmesh(data, obj):
1515
if 'img number' not in data.keys():
1616
data['img number'] = 0
1717

18-
filename = os.path.join(data['output dir'],
19-
'%s_img%03d.png' % (data['base name'],
20-
data['img number'])
21-
)
18+
filename = os.path.join(
19+
data['output dir'],
20+
'%s_img%03d.png' % (data['base name'], data['img number'])
21+
)
2222
data['img number'] = data['img number'] + 1
2323

2424
# Get the dpi for rendering and store the original dpi of the figure
@@ -35,17 +35,23 @@ def draw_quadmesh(data, obj):
3535
obj.draw(ren)
3636

3737
# Generate a image from the render buffer
38-
image = Image.frombuffer('RGBA', ren.get_canvas_width_height(),
39-
ren.buffer_rgba(), 'raw', 'RGBA', 0, 1)
38+
image = Image.frombuffer(
39+
'RGBA',
40+
ren.get_canvas_width_height(),
41+
ren.buffer_rgba(),
42+
'raw', 'RGBA', 0, 1
43+
)
4044
# Crop the image to the actual content (removing the the regions otherwise
4145
# used for axes, etc.)
4246
# 'image.crop' expects the crop box to specify the left, upper, right, and
4347
# lower pixel. 'cbox.extents' gives the left, lower, right, and upper
4448
# pixel.
45-
box = (int(round(cbox.extents[0])),
46-
0,
47-
int(round(cbox.extents[2])),
48-
int(round(cbox.extents[3] - cbox.extents[1])))
49+
box = (
50+
int(round(cbox.extents[0])),
51+
0,
52+
int(round(cbox.extents[2])),
53+
int(round(cbox.extents[3] - cbox.extents[1]))
54+
)
4955
cropped = image.crop(box)
5056
cropped.save(filename)
5157

@@ -55,19 +61,17 @@ def draw_quadmesh(data, obj):
5561
# write the corresponding information to the TikZ file
5662
extent = obj.axes.get_xlim() + obj.axes.get_ylim()
5763

64+
rel_filepath = os.path.basename(filename)
5865
if data['rel data path']:
59-
rel_filepath = os.path.join(data['rel data path'],
60-
os.path.basename(filename)
61-
)
62-
else:
63-
rel_filepath = os.path.basename(filename)
66+
rel_filepath = os.path.join(data['rel data path'], rel_filepath)
6467

6568
# Explicitly use \pgfimage as includegrapics command, as the default
6669
# \includegraphics fails unexpectedly in some cases
67-
content.append('\\addplot graphics [includegraphics cmd=\pgfimage,'
68-
'xmin=%.15g, xmax=%.15g, '
69-
'ymin=%.15g, ymax=%.15g] {%s};\n'
70-
% (extent + (rel_filepath,))
71-
)
70+
content.append(
71+
'\\addplot graphics [includegraphics cmd=\\pgfimage,'
72+
'xmin=%.15g, xmax=%.15g, '
73+
'ymin=%.15g, ymax=%.15g] {%s};\n'
74+
% (extent + (rel_filepath,))
75+
)
7276

7377
return data, content

matplotlib2tikz/save.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# -*- coding: utf-8 -*-
22
#
3+
import codecs
4+
import os
5+
import matplotlib as mpl
6+
37
from . import axes
48
from . import legend
59
from . import line2d
@@ -11,10 +15,6 @@
1115

1216
from .__about__ import __version__
1317

14-
import codecs
15-
import os
16-
import matplotlib as mpl
17-
1818

1919
def get_tikz_code(
2020
filepath,

matplotlib2tikz/text.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# -*- coding: utf-8 -*-
22
#
3-
from . import color
4-
53
import matplotlib as mpl
64

5+
from . import color
6+
77

88
def draw_text(data, obj):
99
'''Paints text on the graph.

0 commit comments

Comments
 (0)