Skip to content

Commit 5e6bbf7

Browse files
committed
minor refactor
1 parent 757e87d commit 5e6bbf7

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

src/tikzplotlib/_axes.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ def _get_tick_position(obj, axes_obj):
541541
if len(set(major_ticks_top)) == 1 and major_ticks_top[0] is True:
542542
major_ticks_top_show_all = True
543543

544+
position_string = None
544545
major_ticks_position = None
545546
if not major_ticks_bottom_show_all and not major_ticks_top_show_all:
546547
position_string = f"{axes_obj}majorticks=false"
@@ -562,31 +563,38 @@ def _get_ticks(data, xy, ticks, ticklabels):
562563
necessary axis options for the given configuration.
563564
"""
564565
axis_options = []
565-
pgfplots_ticks = []
566-
pgfplots_ticklabels = []
566+
567+
# Check if the label is necessary. If one of the labels is, then all of them must
568+
# appear in the TikZ plot.
567569
is_label_required = False
568570
for tick, ticklabel in zip(ticks, ticklabels):
569571
# store the label anyway
570572
label = ticklabel.get_text()
571-
if "," in label:
572-
label = "{" + label + "}"
573573

574-
if ticklabel.get_visible():
575-
pgfplots_ticklabels.append(_common_texification(label))
576-
else:
574+
if not ticklabel.get_visible():
577575
is_label_required = True
576+
break
577+
578+
if not label:
579+
continue
578580

579-
# Check if the label is necessary. If one of the labels is, then all of them
580-
# must appear in the TikZ plot.
581-
if label:
582-
try:
583-
label_float = float(label.replace("\N{MINUS SIGN}", "-"))
584-
except ValueError:
581+
try:
582+
label_float = float(label.replace("\N{MINUS SIGN}", "-"))
583+
except ValueError:
584+
is_label_required = True
585+
break
586+
else:
587+
if abs(label_float - tick) > 1.0e-10 + 1.0e-10 * abs(tick):
585588
is_label_required = True
586-
else:
587-
is_label_required = is_label_required or (
588-
label and abs(label_float - tick) > 1.0e-10 + 1.0e-10 * abs(tick)
589-
)
589+
break
590+
591+
pgfplots_ticks = []
592+
pgfplots_ticklabels = []
593+
for tick, ticklabel in zip(ticks, ticklabels):
594+
label = ticklabel.get_text()
595+
if "," in label:
596+
label = "{" + label + "}"
597+
pgfplots_ticklabels.append(_common_texification(label))
590598

591599
# note: ticks may be present even if labels are not, keep them for grid lines
592600
for tick in ticks:

0 commit comments

Comments
 (0)