@@ -541,6 +541,7 @@ def _get_tick_position(obj, axes_obj):
541
541
if len (set (major_ticks_top )) == 1 and major_ticks_top [0 ] is True :
542
542
major_ticks_top_show_all = True
543
543
544
+ position_string = None
544
545
major_ticks_position = None
545
546
if not major_ticks_bottom_show_all and not major_ticks_top_show_all :
546
547
position_string = f"{ axes_obj } majorticks=false"
@@ -562,27 +563,39 @@ def _get_ticks(data, xy, ticks, ticklabels):
562
563
necessary axis options for the given configuration.
563
564
"""
564
565
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.
567
569
is_label_required = False
568
570
for tick , ticklabel in zip (ticks , ticklabels ):
569
571
# store the label anyway
570
572
label = ticklabel .get_text ()
571
- if "," in label :
572
- label = "{" + label + "}"
573
- if ticklabel .get_visible ():
574
- label = _common_texification (label )
575
- pgfplots_ticklabels .append (label )
576
- else :
573
+
574
+ if not ticklabel .get_visible ():
577
575
is_label_required = True
578
- # Check if the label is necessary. If one of the labels is, then all of them
579
- # must appear in the TikZ plot.
580
- if label :
581
- try :
582
- label_float = float (label .replace ("\N{MINUS SIGN} " , "-" ))
583
- is_label_required = is_label_required or (label and label_float != tick )
584
- except ValueError :
576
+ break
577
+
578
+ if not label :
579
+ continue
580
+
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 ):
585
588
is_label_required = True
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 ))
598
+
586
599
# note: ticks may be present even if labels are not, keep them for grid lines
587
600
for tick in ticks :
588
601
pgfplots_ticks .append (tick )
0 commit comments