@@ -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,27 +563,39 @@ 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 + "}"
573- if ticklabel .get_visible ():
574- label = _common_texification (label )
575- pgfplots_ticklabels .append (label )
576- else :
573+
574+ if not ticklabel .get_visible ():
577575 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 ):
585588 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+
586599 # note: ticks may be present even if labels are not, keep them for grid lines
587600 for tick in ticks :
588601 pgfplots_ticks .append (tick )
0 commit comments