1
1
import matplotlib as mpl
2
+ import math
2
3
import numpy as np
3
4
import re
4
5
from matplotlib .backends .backend_pgf import (
@@ -625,10 +626,16 @@ def _get_ticks(data, xy, ticks, ticklabels):
625
626
pgfplots_ticks .append (tick )
626
627
627
628
# if the labels are all missing, then we need to output an empty set of labels
628
- if len (ticklabels ) == 0 and len (ticks ) != 0 :
629
+ data [f"nticks_{ xy } " ] = len (ticks )
630
+ if len (ticklabels ) == 0 and len (ticks ) != 0 and "minor" not in xy :
629
631
axis_options .append (f"{ xy } ticklabels={{}}" )
630
632
# remove the multiplier too
631
- axis_options .append (f"scaled { xy } ticks=" + r"manual:{}{\pgfmathparse{#1}}" )
633
+ elif "minor" in xy and len (ticks ) != 0 :
634
+ xy_ = xy .split ()[1 ]
635
+ if data [f"nticks_{ xy_ } " ] != 0 :
636
+ multiplier = 5 * math .ceil (len (ticks )/ data [f"nticks_{ xy_ } " ]/ 5 )
637
+ axis_options .append (f"minor { xy_ } tick num={ multiplier } " )
638
+ axis_options .append (f"% { data [f'nticks_{ xy_ } ' ]} ; { len (ticks )} " )
632
639
633
640
# Leave the ticks to PGFPlots if not in STRICT mode and if there are no explicit
634
641
# labels.
@@ -640,9 +647,8 @@ def _get_ticks(data, xy, ticks, ticklabels):
640
647
xy , "," .join ([f"{ el :{ff }} " for el in pgfplots_ticks ])
641
648
)
642
649
)
643
- else :
644
- val = "{}" if "minor" in xy else "\\ empty"
645
- axis_options .append (f"{ xy } tick={ val } " )
650
+ elif "minor" not in xy :
651
+ axis_options .append (f"{ xy } tick=\\ empty" )
646
652
647
653
if is_label_required :
648
654
length = sum (len (label ) for label in pgfplots_ticklabels )
0 commit comments