matplotlib / matplotlib/matplotlib

[Bug]: LogFormatter minor ticks with `minor_thresholds` of (0,0) does not behave as documented

Open
#25,896 2 comments 0 reactions 0 assignees View on GitHub

A pull request for this has already been merged.

  • #29698 by @anntzer — merged
topic: ticks axis labels
Dominant language
Python
Stars
23.2k
Forks
8.5k
Avg merge
1d 6h
Merged PRs (30d)
66

Description

### Bug summary

In investigating #25894 I discovered that despite being documented as:

> To disable labeling of minor ticks when 'labelOnlyBase' is False, use `minor_thresholds=(0, 0)`. This is the default for the "classic" style.

It actually only removes some minor tick labels (e.g. with base of 10: 11-14 will get labels, but 16-19 (15 is edge case, dependent on floating point rounding, 1.4, or 140 also similar))

### Code for reproduction

```python
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker

fig, ax = plt.subplots()
ax.set_yscale("log")

formatter = mticker.LogFormatter(minor_thresholds=(0,0))
ax.yaxis.set_minor_formatter(formatter)

ax.set_ylim(10, 20)
plt.show()
```

### Actual outcome

![Figure_2](https://github.com/matplotlib/matplotlib/assets/2501846/ea3f8e41-0872-42d4-8e5d-c3a479a4f925)

```python
formatter(10) # '10'
formatter(11) # '11'
formatter(12) # '12'
formatter(13) # '13'
formatter(14) # '14'
formatter(15) # '15'
formatter(16) # ''
```

### Expected outcome

![Figure_2](https://github.com/matplotlib/matplotlib/assets/2501846/874d28bb-2f8e-43e1-a3dd-b76dfad64bbf)

```python
formatter(10) # ''
formatter(11) # ''
formatter(12) # ''
formatter(13) # ''
formatter(14) # ''
formatter(15) # ''
formatter(16) # ''
```

### Additional information

Only really affects plots that are zoomed in to much less than one decade, which arguably doesn't make sense to use a log scale, but still seems incongruous with the documented "this turns off minor ticks".

Has to do with when `coeff` rounds down to `1` in:

https://github.com/matplotlib/matplotlib/blob/f051d9449820b5e7c01dcc1361d161517bff179f/lib/matplotlib/ticker.py#L980-L988

I'm not _quite_ sure what the proper solution is, perhaps making `self._sublabels=set()` instead?

### Operating system

Linux

### Matplotlib Version

3.8 (main)

### Matplotlib Backend

_No response_

### Python version

3.11

### Jupyter version

_No response_

### Installation

git checkout

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/matplotlib/ticker.py at the linked lines around 980-988 and reproduce the behavior with LogFormatter(minor_thresholds=(0, 0)) using the example and formatter calls in the issue. The work is done when minor tick labels are consistently empty for this setting, including the zoomed-in range described.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.