proplot-dev / proplot

🎨 A succinct matplotlib wrapper for making beautiful, publication-quality graphics
https://proplot.readthedocs.io
MIT License
1.07k stars 96 forks source link

Bug: xticklabels overwrites xminorticks setting #428

Closed syrte closed 1 year ago

syrte commented 1 year ago

Description

xticklabels overwrites xminorticks setting

Steps to reproduce

Expected behavior with minorticks

fig, ax = pplt.subplot()
ax.format(
    xticks=[0, 0.5, 1], #xticklabels=['a', 'b', 'c'],
    xminorticks=[0.1, 0.2],
)

image

But I got this if setting xticklabels

fig, ax = pplt.subplot()
ax.format(
    xticks=[0, 0.5, 1], xticklabels=['a', 'b', 'c'],
    xminorticks=[0.1, 0.2],
)

image

minorticks are gone...

Proplot version

Paste the results of import matplotlib; print(matplotlib.__version__); import proplot; print(proplot.version) here. 3.4.3 0.9.5.post341

syrte commented 1 year ago

Temporary workaround: Set minor ticks manually after calling ax.format,

ax.set_xticks(tick_list, minor=True)
lukelbd commented 1 year ago

Thanks for the report. Setting minor ticks after major ticks seems to work too:

fig, ax = pplt.subplot()
ax.format(xticks=[0, 0.5, 1], xticklabels=['a', 'b', 'c'])
ax.format(xminorticks=[0.1, 0.2])

iTerm2 F1OMIJ tmp7n9dxpt3

lukelbd commented 1 year ago

This was due to a format() convenience feature: By default, if you pass major ticks labels, minor ticks are disabled, since it's pretty rare that users need both and since proplot changes the default matplotlib style to include minor ticks. This makes the process of setting up manual tick labels take 1 step instead of 2.

However, this should clearly be disabled if a minorlocator is passed in the same call. Fixed by https://github.com/proplot-dev/proplot/commit/a397f81746c6f4e1a97e605f3f6957ef7baeeec4.