Skip to content

Commit 5ffe6ed

Browse files
author
Gorshanov Vadim
committed
Make the minor ticks and minor grid work
1 parent 81507b7 commit 5ffe6ed

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/tikzplotlib/_axes.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import matplotlib as mpl
2+
import math
23
import numpy as np
34
import re
45
from matplotlib.backends.backend_pgf import (
@@ -625,10 +626,16 @@ def _get_ticks(data, xy, ticks, ticklabels):
625626
pgfplots_ticks.append(tick)
626627

627628
# 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:
629631
axis_options.append(f"{xy}ticklabels={{}}")
630632
# 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)}")
632639

633640
# Leave the ticks to PGFPlots if not in STRICT mode and if there are no explicit
634641
# labels.
@@ -640,9 +647,8 @@ def _get_ticks(data, xy, ticks, ticklabels):
640647
xy, ",".join([f"{el:{ff}}" for el in pgfplots_ticks])
641648
)
642649
)
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")
646652

647653
if is_label_required:
648654
length = sum(len(label) for label in pgfplots_ticklabels)

0 commit comments

Comments
 (0)