Skip to content

Commit 7403165

Browse files
committed
Bring minor and major ticks/tickabels to parity
Minor ticklabels were missing altogether,
1 parent 7723fd9 commit 7403165

1 file changed

Lines changed: 28 additions & 29 deletions

File tree

mplexporter/utils.py

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,29 @@ def get_text_style(text):
186186
return style
187187

188188

189+
def _tick_format_props(formatter, tickvalues, labels):
190+
if isinstance(formatter, ticker.NullFormatter):
191+
return "", ""
192+
if isinstance(formatter, ticker.StrMethodFormatter):
193+
convertor = StrMethodTickFormatterConvertor(formatter)
194+
return convertor.output, "str_method"
195+
if isinstance(formatter, ticker.PercentFormatter):
196+
return {
197+
"xmax": formatter.xmax,
198+
"decimals": formatter.decimals,
199+
"symbol": formatter.symbol,
200+
}, "percent"
201+
if hasattr(ticker, 'IndexFormatter') and isinstance(formatter, ticker.IndexFormatter):
202+
return [text.get_text() for text in labels], "index"
203+
if isinstance(formatter, ticker.FixedFormatter):
204+
return list(formatter.seq), "fixed"
205+
if isinstance(formatter, ticker.FuncFormatter) and tickvalues:
206+
return [formatter(value) for value in tickvalues], "func"
207+
if not any(label.get_visible() for label in labels):
208+
return "", ""
209+
return None, ""
210+
211+
189212
def get_axis_properties(axis):
190213
"""Return the property dictionary for a matplotlib.Axis instance"""
191214
props = {}
@@ -215,37 +238,13 @@ def get_axis_properties(axis):
215238
minor_locator = axis.get_minor_locator()
216239
props['minor_tickvalues'] = list(axis.get_minorticklocs()) if minor_locator else None
217240
props['minorticklength'] = axis._minor_tick_kw.get('size', None)
241+
props['majorticklength'] = axis._major_tick_kw.get('size', None)
218242

219243
# Find tick formats
220-
props['tickformat_formatter'] = ""
221-
formatter = axis.get_major_formatter()
222-
if isinstance(formatter, ticker.NullFormatter):
223-
props['tickformat'] = ""
224-
elif isinstance(formatter, ticker.StrMethodFormatter):
225-
convertor = StrMethodTickFormatterConvertor(formatter)
226-
props['tickformat'] = convertor.output
227-
props['tickformat_formatter'] = "str_method"
228-
elif isinstance(formatter, ticker.PercentFormatter):
229-
props['tickformat'] = {
230-
"xmax": formatter.xmax,
231-
"decimals": formatter.decimals,
232-
"symbol": formatter.symbol,
233-
}
234-
props['tickformat_formatter'] = "percent"
235-
elif hasattr(ticker, 'IndexFormatter') and isinstance(formatter, ticker.IndexFormatter):
236-
# IndexFormatter was dropped in matplotlib 3.5
237-
props['tickformat'] = [text.get_text() for text in axis.get_ticklabels()]
238-
props['tickformat_formatter'] = "index"
239-
elif isinstance(formatter, ticker.FixedFormatter):
240-
props['tickformat'] = list(formatter.seq)
241-
props['tickformat_formatter'] = "fixed"
242-
elif isinstance(formatter, ticker.FuncFormatter) and props['tickvalues']:
243-
props['tickformat'] = [formatter(value) for value in props['tickvalues']]
244-
props['tickformat_formatter'] = "func"
245-
elif not any(label.get_visible() for label in axis.get_ticklabels()):
246-
props['tickformat'] = ""
247-
else:
248-
props['tickformat'] = None
244+
props['minor_tickformat'], props['minor_tickformat_formatter'] = _tick_format_props(
245+
axis.get_minor_formatter(), props['minor_tickvalues'], axis.get_minorticklabels())
246+
props['tickformat'], props['tickformat_formatter'] = _tick_format_props(
247+
axis.get_major_formatter(), props['tickvalues'], axis.get_ticklabels())
249248

250249
# Get axis scale
251250
props['scale'] = axis.get_scale()

0 commit comments

Comments
 (0)