Skip to content

AxisItem: Allow hiding minor ticks#3318

Merged
NilsNemitz merged 5 commits intopyqtgraph:masterfrom
2xB:master
Jun 23, 2025
Merged

AxisItem: Allow hiding minor ticks#3318
NilsNemitz merged 5 commits intopyqtgraph:masterfrom
2xB:master

Conversation

@2xB
Copy link
Copy Markdown
Contributor

@2xB 2xB commented Jun 2, 2025

Fixes #3250, which originated from #2827 (therefore maybe @NilsNemitz has an opinion on this?).

This can be used as follows, adapting the example from the above issue:

import pyqtgraph as pg

app = pg.mkQApp()

# Create window
win = pg.GraphicsLayoutWidget(show=True)
win.setWindowTitle('pyqtgraph example: Scrolling Plots')

# Add plot
plot = win.addPlot(1, 1, pen=pg.mkPen(color='#000000'))

# Show grid
plot.showGrid(x=True, y=True)
#plot.getAxis('bottom').style["maxTickLevel"] = 0 # replaced by proper setter thanks to comment by NilsNemitz
#plot.getAxis('left').style["maxTickLevel"] = 0
plot.getAxis('bottom').setStyle(maxTickLevel=0)
plot.getAxis('left').setStyle(maxTickLevel=0)

app.exec()

@mfeingesicht Could you test if this solves your use case?

2xB added 2 commits June 2, 2025 02:27
Fixes pyqtgraph#3250 .

This can be used as follows, adapting the example from the above issue:

```
import pyqtgraph as pg
from PyQt5.QtGui import QGuiApplication

app = pg.mkQApp()

# Create window
win = pg.GraphicsLayoutWidget(show=True)
win.setWindowTitle('pyqtgraph example: Scrolling Plots')

# Add plot
plot = win.addPlot(1, 1, pen=pg.mkPen(color='#000000'))

# Show grid
plot.showGrid(x=True, y=True)
plot.getAxis('bottom').style["maxTickLevel"] = 0
plot.getAxis('left').style["maxTickLevel"] = 0

app.exec()
```
@mfeingesicht
Copy link
Copy Markdown

Hello,

I have just tested this with the newest version (0.13.7) from PyPI, everything works great, thank you very much for this.

@NilsNemitz
Copy link
Copy Markdown
Contributor

Hi @2xB, thank you for adding internal logic for the sub ticks. The code should absolutely have that!

There's probably a follow-up discussion to be had what a reasonable API might look like, since currently AxisItem doesn't really seem to expect the user to interact with its settings very much. For the moment communicating through the style property looks surprisingly reasonable.

#2827 tried to touch the overall logic as little as possible. It tried to adjust the math to produce a helpful number of ticks (e.g. more than one, I think) in a wider range of cases. The same adjustments also allowed the existing minor tick logic to actually produce visible ticks more regularly, I believe that produced the change that #3250 points out.

There's no deeper meaning to the appearance of extra ticks.

@2xB
Copy link
Copy Markdown
Contributor Author

2xB commented Jun 2, 2025

Thank you very much for the responses! Interacting with the style dictionary directly instead of through a proper function is my fault, there already exists a proper interface:

plot.getAxis('bottom').setStyle(maxTickLevel=0)
plot.getAxis('left').setStyle(maxTickLevel=0)

I've also adapted the code in the above message.

@NilsNemitz
Copy link
Copy Markdown
Contributor

@2xB this looks good to me and is a nice, efficiently minimal change.

Could you maybe add a short description of the maxTickLevel parameter to the documentation of setStyle()?

@2xB
Copy link
Copy Markdown
Contributor Author

2xB commented Jun 18, 2025

@NilsNemitz Sure, I added a short documentation to setStyle!

@NilsNemitz
Copy link
Copy Markdown
Contributor

Thank you!

Given the name of the maxTickLevel parameter, I think it might be better if the documentation discusses major ticks and minor ticks here, rather than the grid. Although considering that the grid motivated the PR, maybe

 - 0: Show only major ticks
 - 1: Show major ticks and one level of minor ticks
 - 2: Show two levels of minor ticks (higher CPU usage) 

This setting also affects the displayed grid.

might be a reasonable inclusion?

@2xB
Copy link
Copy Markdown
Contributor Author

2xB commented Jun 18, 2025

Sure! I minorly rephrased it so the grid is mentioned in a concise description at the beginning of the text.

@NilsNemitz
Copy link
Copy Markdown
Contributor

Hi @2xB , we've been having some trouble with the tests, which might be better now.

If you make another change, the tests should rerun automatically, and we'll see. On that note, maybe you could go to line 234 and change

``float``,``int`` or ``None``               to
``float``, ``int`` or ``None``    

?
It's not related to your PR, but it is right next to your maxTickLevel documentation. I hope that will fix the rendering of [int] in the documentation.

Thanks to @NilsNemitz for the suggestion!
@NilsNemitz NilsNemitz merged commit 3596f16 into pyqtgraph:master Jun 23, 2025
36 checks passed
@NilsNemitz
Copy link
Copy Markdown
Contributor

NilsNemitz commented Jun 23, 2025

After #3333 patched up the tests for now, everything comes back green.
I do not see any negative interaction with other parts of the code, and the PR adds in functionality that was clearly missing.

@2xB , thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add option to hide grid on minor ticks

3 participants