Pythonguis iconPythonguisSep 30, 2026 ~5 min source read

Replace numeric axis ticks with string labels in PyQtGraph

Use integer positions as placeholders and supply a list of (position, label) tuples to an axis’s setTicks method to display month names, category names, or any custom strings on a PyQtGraph axis.

Python GUIs: Changing Ticks in PyQtGraph Objects to Strings — How to replace numeric axis ticks with custom labels like month names or dates in PyQtGraph

Share this story

Send the public story page.

Useful takeaways from this story.

Map numeric x values to readable labels by creating a list of (position, label) tuples.

Get the axis object with getAxis("bottom") (or other position) and call setTicks with a list of tick levels: ax.setTicks([labels]).

Wrap your label list inside another list because setTicks accepts multiple tick levels (major/minor).

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.

  1. Prepare your data positions as integers (for example 1..10 for months).
  2. Build label tuples: (position, label) — for months the tutorial uses datetime.date(...).strftime("%B") to produce full month names.
  1. Call 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.

More context around this story.

Python GUIs: Fixing Crashes When Using NumPy Arrays with QImage in Qt Threads — How to safely pass image data between threads when streaming video or updating displays
Pythonguis iconPythonguisSep 9, 2026

Python GUIs: Fixing Crashes When Using NumPy Arrays with QImage in Qt Threads — How to safely pass image data between threads when streaming video or updating displays

I'm using a threaded runner to stream a live video feed by converting a NumPy array to a QImage , then to a QPixmap , and displaying it on a QLabel . But I'm frequently encountering crashes when the label is resized too quickly or the scroll area is scrolled. Could this be a problem with the QImage memory buffer gettin

Python Tkinter: как перестать бояться Canvas и начать рисовать интерфейсы
Habr iconHabrSep 25, 2026

Python Tkinter: как перестать бояться Canvas и начать рисовать интерфейсы

Обычно такие статьи начинаются с банальных вопросов по типу «Что такое интерфейс», «Что такое разработка», «Что такое проектирование». Суть в том, что это не так важно в рамках данной статьи, и к тому же без того интуитивно понятно. Интуитивно понятно также, как и должен быть понятен хороший пользовательский интерфейс!

Python GUIs: Clean up on exit — Stopping threads when closing a PyQt6 application — How to properly shut down background threads and workers when your application window is closed
Pythonguis iconPythonguisSep 9, 2026

Python GUIs: Clean up on exit — Stopping threads when closing a PyQt6 application — How to properly shut down background threads and workers when your application window is closed

I'm using QThreadPool and worker threads in my PyQt application. When I click the X button to close the window, the threads keep running in the background. What's the best way to clean everything up on application exit? This is a very common situation when working with multithreaded PyQt6 applications. You've set up ba

Keep reading in the app

Open the app view to save this story, compare related coverage, and continue from the same source.

Open in app