PyQtGraph plots use numeric values for both axes. When an axis represents categories or named positions (months, weekdays, categories), supply integers in your data as placeholders and map those integers to readable strings for the axis ticks.
Create a list of 2-tuples where each tuple pairs a numeric tick position with a string label, then set those ticks on the axis returned by the plot widget's getAxis method.
- 1Prepare your data positions as integers (for example 1..10 for months).
- 2Build label tuples: (position, label) — for months the tutorial uses datetime.date(...).strftime("%B") to produce full month names.
- 1Call ax.setTicks([month_labels]) — note the outer list: setTicks accepts multiple tick levels, so you pass a list containing your major-tick list.
Example pattern used in the tutorial
- months = [1, 2, 3,..., 10]
- month_labels = [(m, datetime.date(2020, m, 1).strftime("%B")) for m in months]
- ax = self.graphWidget.getAxis("bottom")
- ax.setTicks([month_labels])
The tutorial provides a full runnable PyQt6 + PyQtGraph application that:
- creates a PlotWidget as the central widget of a QMainWindow,
- plots numeric month positions against temperature values,
- sets the plot background to white and uses a red pen for the line,
- computes month_labels as shown above,
- applies the labels with ax.setTicks([month_labels]).
- Always match each label's numeric position to the data point's x value so ticks line up.
- The method works with any string labels (category names like "Apples", "Oranges", etc.).
Use custom string ticks when the numeric axis represents categories, named intervals, or noncontinuous labeled positions where readable labels are more meaningful than raw numbers.
If your x data are 0,1,2,3 for categories: labels = [(0, "Apples"), (1, "Oranges"), (2, "Bananas"), (3, "Grapes")] then ax.setTicks([labels]) will display those names on the axis.
Following this pattern produces a plot where numeric positions remain the data coordinates but the axis displays human-readable labels aligned to those positions.