Skip to content

Commit 53ab5f0

Browse files
committed
pick up some untested lines
1 parent 1264bca commit 53ab5f0

File tree

5 files changed

+38
-51
lines changed

5 files changed

+38
-51
lines changed

matplotlib2tikz/axes.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ def __init__(self, data, obj):
3232

3333
self.nsubplots = geom[0] * geom[1]
3434
if self.nsubplots > 1:
35-
is_groupplot = True
3635
# Is this an axis-colorbar pair? No need for groupplot then.
37-
if self.nsubplots == 2 and _find_associated_colorbar(obj):
38-
is_groupplot = False
36+
is_groupplot = \
37+
self.nsubplots != 2 or not _find_associated_colorbar(obj)
3938

4039
if is_groupplot:
4140
self.is_subplot = True
@@ -179,10 +178,9 @@ def __init__(self, data, obj):
179178
y_tick_dirs = [tick._tickdir for tick in obj.yaxis.get_major_ticks()]
180179
if x_tick_dirs or y_tick_dirs:
181180
if x_tick_dirs and y_tick_dirs:
182-
if x_tick_dirs[0] == y_tick_dirs[0]:
183-
direction = x_tick_dirs[0]
184-
else:
185-
direction = None
181+
direction = \
182+
x_tick_dirs[0] if x_tick_dirs[0] == y_tick_dirs[0] \
183+
else None
186184
elif x_tick_dirs:
187185
direction = x_tick_dirs[0]
188186
else:
@@ -559,10 +557,8 @@ def _get_ticks(data, xy, ticks, ticklabels):
559557
)
560558
)
561559
else:
562-
if 'minor' in xy:
563-
axis_options.append('%stick={}' % xy)
564-
else:
565-
axis_options.append('%stick=\\empty' % xy)
560+
val = '{}' if 'minor' in xy else '\\empty'
561+
axis_options.append('%stick=%s' % (xy, val))
566562

567563
if is_label_required:
568564
axis_options.append('%sticklabels={%s}'
@@ -602,12 +598,10 @@ def _mpl_cmap2pgf_cmap(cmap):
602598
'''
603599
if isinstance(cmap, mpl.colors.LinearSegmentedColormap):
604600
return _handle_linear_segmented_color_map(cmap)
605-
elif isinstance(cmap, mpl.colors.ListedColormap):
606-
return _handle_listed_color_map(cmap)
607-
else:
608-
raise RuntimeError(
609-
'Only LinearSegmentedColormap and ListedColormap are supported'
610-
)
601+
602+
assert isinstance(cmap, mpl.colors.ListedColormap), \
603+
'Only LinearSegmentedColormap and ListedColormap are supported'
604+
return _handle_listed_color_map(cmap)
611605

612606

613607
def _handle_linear_segmented_color_map(cmap):

matplotlib2tikz/image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ def draw_image(data, obj):
5151
# write the corresponding information to the TikZ file
5252
extent = obj.get_extent()
5353

54-
# the format specification will only accept tuples, not lists
55-
if isinstance(extent, list): # convert to () list
54+
# the format specification will only accept tuples
55+
if not isinstance(extent, tuple):
5656
extent = tuple(extent)
5757

5858
rel_filepath = os.path.basename(filename)

matplotlib2tikz/line2d.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,17 @@ def draw_linecollection(data, obj):
200200
return data, content
201201

202202

203+
TIKZ_LINEWIDTHS = {
204+
0.1: 'ultra thin',
205+
0.2: 'very thin',
206+
0.4: 'thin',
207+
0.6: 'semithick',
208+
0.8: 'thick',
209+
1.2: 'very thick',
210+
1.6: 'ultra thick'
211+
}
212+
213+
203214
def _mpl_linewidth2pgfp_linewidth(data, line_width):
204215
if data['strict']:
205216
# Takes the matplotlib linewidths, and just translate them
@@ -297,7 +308,7 @@ def _mpl_marker2pgfp_marker(data, mpl_marker, marker_face_color):
297308
if mpl_marker == ',':
298309
print('Unsupported marker '','' (pixel).')
299310

300-
return (data, None, None)
311+
return data, None, None
301312

302313

303314
_MPLLINESTYLE_2_PGFPLOTSLINESTYLE = {
@@ -348,13 +359,3 @@ def _mpl_linestyle2pgfp_linestyle(line_style):
348359
# % e
349360
# )
350361
# return (xdata, ydata)
351-
352-
353-
TIKZ_LINEWIDTHS = {0.1: 'ultra thin',
354-
0.2: 'very thin',
355-
0.4: 'thin',
356-
0.6: 'semithick',
357-
0.8: 'thick',
358-
1.2: 'very thick',
359-
1.6: 'ultra thick'
360-
}

matplotlib2tikz/path.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,8 @@ def draw_path(data, path, draw_options=None, simplify=None):
7676
# Store the previous point for quadratic Beziers.
7777
prev = vert[0:2]
7878

79-
nodes_string = '\n'.join(nodes)
80-
if draw_options:
81-
path_command = '\\path [%s] %s;\n\n' % \
82-
(', '.join(draw_options), nodes_string)
83-
else:
84-
path_command = '\\path %s;\n\n' % nodes_string
79+
do = '[{}]'.format(', '.join(draw_options)) if draw_options else ''
80+
path_command = '\\path {} {};\n\n'.format(do, '\n'.join(nodes))
8581

8682
return data, path_command
8783

@@ -146,15 +142,12 @@ def draw_pathcollection(data, obj):
146142
'{/tikz/mark size=\\perpointmarksize}',
147143
])
148144

149-
if draw_options:
150-
content.append('\\addplot [%s]\n' % (', '.join(draw_options)))
151-
else:
152-
content.append('\\addplot\n')
145+
do = ' [{}]'.format(', '.join(draw_options)) if draw_options else ''
146+
content.append('\\addplot{}\n'.format(do))
147+
148+
to = ' [{}]'.format(', '.join(table_options)) if table_options else ''
149+
content.append('table{}{{%\n'.format(to))
153150

154-
if table_options:
155-
content.append('table [%s]{%%\n' % ', '.join(table_options))
156-
else:
157-
content.append('table {%\n')
158151
content.append((' '.join(labels)).strip() + '\n')
159152
fmt = (' '.join(dd.shape[1] * ['%+.15e'])) + '\n'
160153
for d in dd:

matplotlib2tikz/save.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,13 @@ def get_tikz_code(
134134
else:
135135
data['extra axis options [base]'] = set()
136136

137-
if dpi is None:
138-
savefig_dpi = mpl.rcParams['savefig.dpi']
139-
if isinstance(savefig_dpi, int):
140-
data['dpi'] = savefig_dpi
141-
else:
142-
data['dpi'] = mpl.rcParams['figure.dpi']
143-
else:
137+
if dpi:
144138
data['dpi'] = dpi
139+
else:
140+
savefig_dpi = mpl.rcParams['savefig.dpi']
141+
data['dpi'] = \
142+
savefig_dpi if isinstance(savefig_dpi, int) \
143+
else mpl.rcParams['figure.dpi']
145144

146145
# gather the file content
147146
data, content = _recurse(data, figure)

0 commit comments

Comments
 (0)