Skip to content

Commit 043a552

Browse files
committed
more lint fixes
1 parent cd20103 commit 043a552

File tree

1 file changed

+113
-105
lines changed

1 file changed

+113
-105
lines changed

matplotlib2tikz/axes.py

Lines changed: 113 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -201,20 +201,18 @@ def __init__(self, data, obj):
201201

202202
# Set each rotation for every label
203203
x_tick_rotation_and_horizontal_alignment = \
204-
self.__get_label_rotation_and_horizontal_alignment(obj, data, 'x')
204+
_get_label_rotation_and_horizontal_alignment(obj, data, 'x')
205205
if x_tick_rotation_and_horizontal_alignment:
206206
self.axis_options.append(x_tick_rotation_and_horizontal_alignment)
207207

208208
y_tick_rotation_and_horizontal_alignment = \
209-
self.__get_label_rotation_and_horizontal_alignment(obj, data, 'y')
209+
_get_label_rotation_and_horizontal_alignment(obj, data, 'y')
210210
if y_tick_rotation_and_horizontal_alignment:
211211
self.axis_options.append(y_tick_rotation_and_horizontal_alignment)
212212

213213
# Set tick position
214-
x_tick_position_string, x_tick_position = \
215-
self.__get_tick_position(obj, data, 'x')
216-
y_tick_position_string, y_tick_position = \
217-
self.__get_tick_position(obj, data, 'y')
214+
x_tick_position_string, x_tick_position = _get_tick_position(obj, 'x')
215+
y_tick_position_string, y_tick_position = _get_tick_position(obj, 'y')
218216

219217
if x_tick_position == y_tick_position and x_tick_position is not None:
220218
self.axis_options.append("tick pos=%s" % x_tick_position)
@@ -389,128 +387,138 @@ def __init__(self, data, obj):
389387

390388
return
391389

392-
def __get_label_rotation_and_horizontal_alignment(self, obj, data, axes):
393-
tick_label_text_width = None
394-
tick_label_text_width_identifier = "%s tick label text width" % axes
395-
if tick_label_text_width_identifier in data['extra axis options']:
396-
tick_label_text_width = data['extra axis options [base]'][
397-
tick_label_text_width_identifier
398-
]
399-
del data['extra axis options'][tick_label_text_width_identifier]
390+
def get_begin_code(self):
391+
content = self.content
392+
if self.axis_options:
393+
content.append('[\n' + ',\n'.join(self.axis_options) + '\n]\n')
394+
return content
400395

401-
label_style = ""
396+
def get_end_code(self, data):
397+
if not self.is_subplot:
398+
return '\\end{axis}\n\n'
399+
elif self.is_subplot and self.nsubplots == self.subplot_index:
400+
data['is_in_groupplot_env'] = False
401+
return '\\end{groupplot}\n\n'
402+
else:
403+
return ''
402404

403-
major_tick_labels = obj.xaxis.get_majorticklabels() if axes == 'x' \
404-
else obj.yaxis.get_majorticklabels()
405405

406-
if len(major_tick_labels) == 0:
407-
return None
406+
def _get_label_rotation_and_horizontal_alignment(
407+
obj, data, axes_obj
408+
):
409+
tick_label_text_width = None
410+
tick_label_text_width_identifier = \
411+
'%s tick label text width' % axes_obj
412+
if tick_label_text_width_identifier in data['extra axis options']:
413+
tick_label_text_width = data['extra axis options [base]'][
414+
tick_label_text_width_identifier
415+
]
416+
del data['extra axis options'][tick_label_text_width_identifier]
408417

409-
tick_labels_rotation = \
410-
[label.get_rotation() for label in major_tick_labels]
411-
tick_labels_rotation_same_value = len(set(tick_labels_rotation)) == 1
418+
label_style = ""
412419

413-
tick_labels_horizontal_alignment = \
414-
[label.get_horizontalalignment() for label in major_tick_labels]
415-
tick_labels_horizontal_alignment_same_value = \
416-
len(set(tick_labels_horizontal_alignment)) == 1
420+
major_tick_labels = \
421+
obj.xaxis.get_majorticklabels() if axes_obj == 'x' \
422+
else obj.yaxis.get_majorticklabels()
417423

418-
if tick_labels_rotation_same_value and \
419-
tick_labels_horizontal_alignment_same_value:
420-
values = []
424+
if len(major_tick_labels) == 0:
425+
return None
421426

422-
if any(tick_labels_rotation) != 0:
423-
values.append('rotate=%d' % tick_labels_rotation[0])
427+
tick_labels_rotation = \
428+
[label.get_rotation() for label in major_tick_labels]
429+
tick_labels_rotation_same_value = len(set(tick_labels_rotation)) == 1
424430

425-
if tick_label_text_width:
426-
values.append('align=%s' % tick_labels_horizontal_alignment[0])
427-
values.append('text width=%s' % tick_label_text_width)
428-
else:
429-
print('Horizontal alignment will be ignored as no \'%s tick '
430-
'label text width\' has been passed in the \'extra\' '
431-
'parameter' % axes)
431+
tick_labels_horizontal_alignment = \
432+
[label.get_horizontalalignment() for label in major_tick_labels]
433+
tick_labels_horizontal_alignment_same_value = \
434+
len(set(tick_labels_horizontal_alignment)) == 1
435+
436+
if tick_labels_rotation_same_value and \
437+
tick_labels_horizontal_alignment_same_value:
438+
values = []
432439

433-
if len(values) > 0:
434-
label_style = \
435-
'%sticklabel style = {%s}' % (axes, ','.join(values))
440+
if any(tick_labels_rotation) != 0:
441+
values.append('rotate=%d' % tick_labels_rotation[0])
442+
443+
if tick_label_text_width:
444+
values.append('align=%s' % tick_labels_horizontal_alignment[0])
445+
values.append('text width=%s' % tick_label_text_width)
436446
else:
437-
values = []
447+
print('Horizontal alignment will be ignored as no \'%s tick '
448+
'label text width\' has been passed in the \'extra\' '
449+
'parameter' % axes_obj)
438450

439-
if tick_labels_rotation_same_value:
440-
values.append('rotate=%d' % tick_labels_rotation[0])
441-
else:
442-
values.append('rotate={%s,0}[\\ticknum]'
443-
% ','.join(str(x) for x in tick_labels_rotation))
444-
445-
if tick_label_text_width:
446-
if tick_labels_horizontal_alignment_same_value:
447-
values.append('align=%s' %
448-
tick_labels_horizontal_alignment[0])
449-
values.append('text width=%s' % tick_label_text_width)
450-
else:
451-
for idx, x in enumerate(tick_labels_horizontal_alignment):
452-
label_style += '%s_tick_label_ha_%d/.initial = %s' \
453-
% (axes, idx, x)
454-
455-
values.append(
456-
'align=\\pgfkeysvalueof{/pgfplots/'
457-
'%s_tick_label_ha_\\ticknum}' % axes)
458-
values.append('text width=%s' % tick_label_text_width)
451+
if len(values) > 0:
452+
label_style = \
453+
'%sticklabel style = {%s}' % (axes_obj, ','.join(values))
454+
else:
455+
values = []
456+
457+
if tick_labels_rotation_same_value:
458+
values.append('rotate=%d' % tick_labels_rotation[0])
459+
else:
460+
values.append('rotate={%s,0}[\\ticknum]'
461+
% ','.join(str(x) for x in tick_labels_rotation))
462+
463+
if tick_label_text_width:
464+
if tick_labels_horizontal_alignment_same_value:
465+
values.append('align=%s' %
466+
tick_labels_horizontal_alignment[0])
467+
values.append('text width=%s' % tick_label_text_width)
459468
else:
460-
print('Horizontal alignment will be ignored as no \'%s tick '
461-
'label text width\' has been passed in the \'extra\' '
462-
'parameter' % axes)
469+
for idx, x in enumerate(tick_labels_horizontal_alignment):
470+
label_style += '%s_tick_label_ha_%d/.initial = %s' \
471+
% (axes_obj, idx, x)
463472

464-
label_style = 'every %s tick label/.style = {\n' \
465-
'%s\n' \
466-
'}' % (axes, ',\n'.join(values))
473+
values.append(
474+
'align=\\pgfkeysvalueof{/pgfplots/'
475+
'%s_tick_label_ha_\\ticknum}' % axes_obj
476+
)
477+
values.append('text width=%s' % tick_label_text_width)
478+
else:
479+
print(
480+
'Horizontal alignment will be ignored as no \'%s tick '
481+
'label text width\' has been passed in the \'extra\' '
482+
'parameter' % axes_obj
483+
)
467484

468-
return label_style
485+
label_style = 'every %s tick label/.style = {\n' \
486+
'%s\n' \
487+
'}' % (axes_obj, ',\n'.join(values))
469488

470-
def __get_tick_position(self, obj, data, axes):
471-
major_ticks = obj.xaxis.majorTicks if axes == 'x' else \
472-
obj.yaxis.majorTicks
489+
return label_style
473490

474-
major_ticks_bottom = [tick.tick1On for tick in major_ticks]
475-
major_ticks_top = [tick.tick2On for tick in major_ticks]
476491

477-
major_ticks_bottom_show_all = False
478-
if len(set(major_ticks_bottom)) == 1 and major_ticks_bottom[0] is True:
479-
major_ticks_bottom_show_all = True
492+
def _get_tick_position(obj, axes_obj):
493+
major_ticks = obj.xaxis.majorTicks if axes_obj == 'x' else \
494+
obj.yaxis.majorTicks
480495

481-
major_ticks_top_show_all = False
482-
if len(set(major_ticks_top)) == 1 and major_ticks_top[0] is True:
483-
major_ticks_top_show_all = True
496+
major_ticks_bottom = [tick.tick1On for tick in major_ticks]
497+
major_ticks_top = [tick.tick2On for tick in major_ticks]
484498

485-
major_ticks_position = None
486-
if not major_ticks_bottom_show_all and not major_ticks_top_show_all:
487-
position_string = "%smajorticks=false" % axes
488-
elif major_ticks_bottom_show_all and major_ticks_top_show_all:
489-
major_ticks_position = 'both'
490-
elif major_ticks_bottom_show_all:
491-
major_ticks_position = 'left'
492-
elif major_ticks_top_show_all:
493-
major_ticks_position = 'right'
499+
major_ticks_bottom_show_all = False
500+
if len(set(major_ticks_bottom)) == 1 and major_ticks_bottom[0] is True:
501+
major_ticks_bottom_show_all = True
494502

495-
if major_ticks_position:
496-
position_string = "%stick pos=%s" % (axes, major_ticks_position)
503+
major_ticks_top_show_all = False
504+
if len(set(major_ticks_top)) == 1 and major_ticks_top[0] is True:
505+
major_ticks_top_show_all = True
497506

498-
return position_string, major_ticks_position
507+
major_ticks_position = None
508+
if not major_ticks_bottom_show_all and not major_ticks_top_show_all:
509+
position_string = "%smajorticks=false" % axes_obj
510+
elif major_ticks_bottom_show_all and major_ticks_top_show_all:
511+
major_ticks_position = 'both'
512+
elif major_ticks_bottom_show_all:
513+
major_ticks_position = 'left'
514+
elif major_ticks_top_show_all:
515+
major_ticks_position = 'right'
499516

500-
def get_begin_code(self):
501-
content = self.content
502-
if self.axis_options:
503-
content.append('[\n' + ',\n'.join(self.axis_options) + '\n]\n')
504-
return content
517+
if major_ticks_position:
518+
position_string = \
519+
"%stick pos=%s" % (axes_obj, major_ticks_position)
505520

506-
def get_end_code(self, data):
507-
if not self.is_subplot:
508-
return '\\end{axis}\n\n'
509-
elif self.is_subplot and self.nsubplots == self.subplot_index:
510-
data['is_in_groupplot_env'] = False
511-
return '\\end{groupplot}\n\n'
512-
else:
513-
return ''
521+
return position_string, major_ticks_position
514522

515523

516524
def _get_ticks(data, xy, ticks, ticklabels):

0 commit comments

Comments
 (0)