Use AxisItem.setTicks() for a fixed set of labels, override tickStrings() when labels should be calculated from tick values, and use DateAxisItem when your x coordinates are Unix timestamps. In all cases, keep the plotted coordinates numeric and make sure the tick positions match them.
Choose the right method for your x values
| What your x values represent | Use | How it works |
|---|---|---|
| Known numeric positions for categories, such as 0, 1, 2 | AxisItem.setTicks() |
Provide explicit pairs of numeric positions and display labels. This sets which ticks appear and overrides the normal automatic tick calculation and formatting. PyQtGraph AxisItem API. |
| Numeric values whose labels need to be computed | Override AxisItem.tickStrings() |
Return one display string for each tick value PyQtGraph supplies. PyQtGraph AxisItem API. |
| Actual dates stored as Unix timestamps | DateAxisItem |
Formats timestamp coordinates as dates and adapts the displayed format to the time density visible on the axis. PyQtGraph DateAxisItem API. |
Set fixed labels at known numeric positions
For a short, fixed sequence such as month names on ordinal x positions, get the bottom axis and pass tick levels to setTicks(). Each tick is a (numeric_position, label) pair:
As an Amazon Associate I earn from qualifying purchases.
import pyqtgraph as pg
plot = pg.PlotWidget()
axis = plot.getAxis('bottom')
axis.setTicks([[(0, 'Jan'), (1, 'Feb'), (2, 'Mar')]])
The numbers in those pairs must be the x coordinates used by the plotted data. For example, if the data points are at 0, 1, and 2, the labels above align with them. A label pair changes the tick location and its displayed text; it does not convert string categories into plotting coordinates. Keep the data numeric and map each label to the corresponding numeric position.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
setTicks() takes nested tick levels: the inner list contains the position-label pairs for a level. The documented format supports major and minor levels, with a third optional level. Because explicit ticks take precedence over the usual tickSpacing(), tickValues(), and tickStrings() behavior, use this method when you intend to control the ticks directly—not when you want PyQtGraph to keep selecting them automatically.
#1 Best Overall
Format real date and time coordinates
If x data contains Unix timestamps, use DateAxisItem rather than maintaining a fixed label list. It chooses date formatting according to the visible time density, which is useful as the plotted range changes.
import pyqtgraph as pg
plot = pg.PlotWidget()
axis = pg.DateAxisItem(orientation='bottom')
plot.setAxisItems({'bottom': axis})
Plot timestamp-valued x coordinates with this axis. The axis constructor also accepts an optional utcOffset; decide the timezone semantics for both the data and the display instead of assuming the offset is handled in a particular way. The concise API reference documents the parameter but does not detail its conversion rules. The API reference currently identifies itself as PyQtGraph 0.15.0.dev0, so confirm behavior against the version installed in your application.
Rank #2
Do not pass ordinal month positions such as 0, 1, and 2 to DateAxisItem as if they were timestamps. Use explicit labels or custom formatting for ordinal values.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchGenerate labels from tick values
For labels that should be calculated rather than listed as fixed pairs, subclass AxisItem and override tickStrings(values, scale, spacing). Return a string for every supplied value:
import pyqtgraph as pg
class MonthAxis(pg.AxisItem):
def tickStrings(self, values, scale, spacing):
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
return [months[int(value) % 12] for value in values]
This example assumes integer-like values used as month indices. It does not represent years or distinguish, for example, January in different years. For timestamps or ranges that cross year boundaries, format the actual date values with DateAxisItem or write a formatter that interprets the data representation correctly.
In logarithmic mode, PyQtGraph routes tick-string generation through logTickStrings(), which is also an override point. See the AxisItem API reference for the tick-formatting methods.
Prevent labels from being clipped or overlapping
Custom labels may need more room than numeric ticks, especially on a narrow plot. AxisItem.setStyle() documents controls including autoExpandTextSpace, autoReduceTextSpace, hideOverlappingLabels, and tick-text width and height limits. Horizontal axes hide labels that extend beyond the axis geometry by default; vertical axes permit extension by default. Check the result at the target window size and font, and adjust axis style if labels overlap or are cut off. See the AxisItem style and tick API.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




